SICP

S W
SICP 二章 2013年 7月
2.1.1-2.1.4
Cons(truct)
(define x (cons 1 2))
car cdr
高階層化可能
(car (cdr z ))
(Car x ) : 1
(Cdr x ) : 2
データ抽象(階層)
四角形の定義
面積、周辺長さの計
算
面積、周辺長さの計
算
幅と高さの計算
四角形の定義
ラムダ計算 非形式的な概説
(wiki)
例えば、ある数に 2 を加える関数 f を考える。これは通常の書き方では
f(x) = x + 2 と書くことができるだろう。この関数 f は、ラムダ計算の式
(ラムダ式という)では λx. x + 2 と書かれる。変数 x の名前は重要では
なく、 λy. y + 2 と書いても同じである。同様に、この関数に 3 を適用し
た結果の数 f(3) は (λx. x + 2) 3 と書かれる。関数の適用は左結合である。
つまり、 f x y = (f x) y である。今度は、引数(関数の入力)に関数をとり
それに 3 を適用する関数を考えてみよう。これはラムダ式では λf. f 3 と
なる。この関数に、先ほど作った 2 を加える関数を適用すると、 (λf. f 3)
(λx. x + 2) となる。ここで、
(λf. f 3) (λx. x + 2) と (λx. x + 2) 3 と 3 + 2
の3つの表現はいずれも同値である。
Church数 (wikipedia)
0 ≡ λf.λx. X
1 ≡ λf.λx. f x
2 ≡ λf.λx. f (f x)
3 ≡ λf.λx. f (f (f x))...
n ≡ λf.λx. fn x...
直感的には、数 n はラムダ式では f という関数
をもらってそれを n 回適用したものを返す関数
である。つまり、チャーチ数は1引数関数を受け
取り、1引数関数を返す高階関数である。
Church数
○n+1
n を受け取って n + 1 を返す関数を定
義することができる。
SUCC := λn f x. f (n f x)
Church数
○掛け算 m*n
MULT := λm n. m (PLUS n) 0
この定義は、 m と n の乗算は、 0 に n を m回
加えることと等しい、ということを利用して
作られている。
MULT := λm n f. m (n f)
問 2.5
(define (print-point p)
(newline)
(display "(")
(display (car p))
(display ",")
(display (cdr p))
(display ")"))
; devide by 2
(define (getcar n)
(getcar-iter n 0))
(define (getcar-iter n a)
(if (= (remainder n 2) 0)
(getcar-iter (/ n 2) (+ a 1))
a))
; devide by 3
(define (getcdr n)
(getcdr-iter n 0))
(define (getcdr-iter n b)
(if (= (remainder n 3) 0)
(getcdr-iter (/ n 3) (+ b 1))
b))
(define (get-num n )
(cons (getcar n) (getcdr n)))
(define p (get-num 9))
(print-point p)
コメント 赤字が追加部分
remainderのサブルーチンは共通化できるが未実施
(0,2)
問 2.6
; n+1
(define (add1 n) (lambda (f) (lambda (x) (f ((n f) x)))))
;0
(define zero (lambda (f) (lambda (x) x)))
; 1= ramuda f x f x
;;;(print "cunning") ; from danboykis.com
;;;(add-1 zero)
;;;(add-1 (lambda (f) (lambda (x) x)))
;;;(lambda (f) (lambda (x) (f (((lambda (f) (lambda (x) x)) f) x))))
;;;(lambda (f) (lambda (x) (f ((lambda (x) x) x))))
;;;(lambda (f) (lambda (x) (f x)))
(define one (lambda (f) (lambda (x) (f x ))))
;2
(define two (lambda (f) (lambda (x) (f(f x)))))
;3
(define three (lambda (f) (lambda (x) (f(f(f x))))))
問 2.6 その2
;m+n
(define (addc m n) (lambda (f) (lambda (x) ((m f) ((n f) x)))))
;;;;;;; verification
(define (inc n) (+ n 1))
(print ((zero inc) 0))
(print ((one inc) 0))
(print ((two inc) 0))
(print ((three inc) 0))
(print (((add1 zero) inc) 0))
(print (((add1 one) inc) 0))
(define (bai n) (* n 2))
(print ((one bai) 1))
(print ((two bai) 1))
(print ((three bai) 1)) ;;;;; Question ;;;;;;;
(print "1+3=")
(print (((addc one three) inc) 0))
;(print (((addc2 one three) inc) 0))
(print (((addc one three) bai) 1)) ;;;;; Question ;;;;;
(print (((addc three three) bai) 1)) ;;;;; Question ;;;;;
1 de 10

Recomendados

04.第四章用Matlab求偏导数 por
04.第四章用Matlab求偏导数04.第四章用Matlab求偏导数
04.第四章用Matlab求偏导数Xin Zheng
4.5K vistas1 diapositiva
RでGISハンズオンセッション por
RでGISハンズオンセッションRでGISハンズオンセッション
RでGISハンズオンセッションarctic_tern265
3.4K vistas26 diapositivas
for関数を使った繰り返し処理によるヒストグラムの一括出力 por
for関数を使った繰り返し処理によるヒストグラムの一括出力for関数を使った繰り返し処理によるヒストグラムの一括出力
for関数を使った繰り返し処理によるヒストグラムの一括出力imuyaoti
12.5K vistas35 diapositivas
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg... por
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...Masahiro Sakai
1.3K vistas27 diapositivas
ggplot2 110129 por
ggplot2 110129ggplot2 110129
ggplot2 110129Takashi Minoda
6.1K vistas28 diapositivas
円と円の交点の求め方 por
円と円の交点の求め方円と円の交点の求め方
円と円の交点の求め方Sho IIZUKA
2.4K vistas12 diapositivas

Más contenido relacionado

La actualidad más candente

20130921_曲面の微分幾何学 por
20130921_曲面の微分幾何学20130921_曲面の微分幾何学
20130921_曲面の微分幾何学matsumoring
2.8K vistas30 diapositivas
python-geohex por
python-geohexpython-geohex
python-geohex遼 会田
748 vistas28 diapositivas
ggplot2再入門(2015年バージョン) por
ggplot2再入門(2015年バージョン)ggplot2再入門(2015年バージョン)
ggplot2再入門(2015年バージョン)yutannihilation
65.7K vistas77 diapositivas
Ilerpg Study 002 por
Ilerpg Study 002Ilerpg Study 002
Ilerpg Study 002Yoshiki Ushida
1.2K vistas17 diapositivas
llvm入門 por
llvm入門llvm入門
llvm入門MITSUNARI Shigeo
16.6K vistas19 diapositivas
CG2013 07 por
CG2013 07CG2013 07
CG2013 07shiozawa_h
761 vistas9 diapositivas

La actualidad más candente(20)

20130921_曲面の微分幾何学 por matsumoring
20130921_曲面の微分幾何学20130921_曲面の微分幾何学
20130921_曲面の微分幾何学
matsumoring2.8K vistas
python-geohex por 遼 会田
python-geohexpython-geohex
python-geohex
遼 会田748 vistas
ggplot2再入門(2015年バージョン) por yutannihilation
ggplot2再入門(2015年バージョン)ggplot2再入門(2015年バージョン)
ggplot2再入門(2015年バージョン)
yutannihilation65.7K vistas
kagamicomput201806 por swkagami
kagamicomput201806kagamicomput201806
kagamicomput201806
swkagami275 vistas
3次元の凸包を求める por abc3141
3次元の凸包を求める3次元の凸包を求める
3次元の凸包を求める
abc31414.8K vistas
プログラミング言語 Julia の紹介 por Kentaro Iizuka
プログラミング言語 Julia の紹介プログラミング言語 Julia の紹介
プログラミング言語 Julia の紹介
Kentaro Iizuka33.5K vistas
データとは何か por Kenta Suzuki
データとは何かデータとは何か
データとは何か
Kenta Suzuki3.7K vistas
OpenGLと行列 por miyosuda
OpenGLと行列OpenGLと行列
OpenGLと行列
miyosuda4.9K vistas
kagamicomput201707 por swkagami
kagamicomput201707kagamicomput201707
kagamicomput201707
swkagami453 vistas
Ninja of Train por tomerun
Ninja of TrainNinja of Train
Ninja of Train
tomerun380 vistas
UTPC2012 - K por omeometo
UTPC2012 - KUTPC2012 - K
UTPC2012 - K
omeometo303 vistas
Precise garbage collection for c por miura1729
Precise garbage collection for cPrecise garbage collection for c
Precise garbage collection for c
miura17292.6K vistas

Destacado

Grace por
GraceGrace
Gracealbanks96
375 vistas15 diapositivas
Cultura Digital por
Cultura DigitalCultura Digital
Cultura DigitalOswaldo Lorenzo
1K vistas14 diapositivas
Sia_final2016 por
Sia_final2016Sia_final2016
Sia_final2016Elias Emmanuel Rainao Wistuba
94 vistas1 diapositiva
Enterprise applications diffusion within organizations: A social learning per... por
Enterprise applications diffusion within organizations: A social learning per...Enterprise applications diffusion within organizations: A social learning per...
Enterprise applications diffusion within organizations: A social learning per...Oswaldo Lorenzo
449 vistas21 diapositivas
Cicadas- Math por
Cicadas- MathCicadas- Math
Cicadas- Mathljanita
199 vistas3 diapositivas
Rakuten Hackathon 2014 por
Rakuten Hackathon 2014Rakuten Hackathon 2014
Rakuten Hackathon 2014S W
601 vistas5 diapositivas

Destacado(11)

Enterprise applications diffusion within organizations: A social learning per... por Oswaldo Lorenzo
Enterprise applications diffusion within organizations: A social learning per...Enterprise applications diffusion within organizations: A social learning per...
Enterprise applications diffusion within organizations: A social learning per...
Oswaldo Lorenzo449 vistas
Cicadas- Math por ljanita
Cicadas- MathCicadas- Math
Cicadas- Math
ljanita199 vistas
Rakuten Hackathon 2014 por S W
Rakuten Hackathon 2014Rakuten Hackathon 2014
Rakuten Hackathon 2014
S W601 vistas
Facebook Pages Customizations por Rahul Singh
Facebook Pages CustomizationsFacebook Pages Customizations
Facebook Pages Customizations
Rahul Singh232 vistas
The smart manager on technology por Oswaldo Lorenzo
The smart manager on technologyThe smart manager on technology
The smart manager on technology
Oswaldo Lorenzo333 vistas
Study latin por S W
Study latinStudy latin
Study latin
S W374 vistas
Maximizing business value from information technology investment por Oswaldo Lorenzo
Maximizing business value from information technology investmentMaximizing business value from information technology investment
Maximizing business value from information technology investment
Oswaldo Lorenzo2.3K vistas
Process based management examples of information technology enablers por Oswaldo Lorenzo
Process based management examples of information technology enablersProcess based management examples of information technology enablers
Process based management examples of information technology enablers
Oswaldo Lorenzo1.7K vistas

Similar a SICP

代数的実数とCADの実装紹介 por
代数的実数とCADの実装紹介代数的実数とCADの実装紹介
代数的実数とCADの実装紹介Masahiro Sakai
3.8K vistas71 diapositivas
Introduction to Categorical Programming (Revised) por
Introduction to Categorical Programming (Revised)Introduction to Categorical Programming (Revised)
Introduction to Categorical Programming (Revised)Masahiro Sakai
6.4K vistas53 diapositivas
Church Numerals por
Church NumeralsChurch Numerals
Church NumeralsMasato HORINOUCHI
229 vistas11 diapositivas
Slide por
SlideSlide
SlideTakefumi MIYOSHI
1.2K vistas26 diapositivas
Haskell勉強会 14.1〜14.3 の説明資料 por
Haskell勉強会 14.1〜14.3 の説明資料Haskell勉強会 14.1〜14.3 の説明資料
Haskell勉強会 14.1〜14.3 の説明資料Etsuji Nakai
2.5K vistas37 diapositivas
表現行列問題 por
表現行列問題表現行列問題
表現行列問題政孝 鍋島
25 vistas4 diapositivas

Similar a SICP(20)

代数的実数とCADの実装紹介 por Masahiro Sakai
代数的実数とCADの実装紹介代数的実数とCADの実装紹介
代数的実数とCADの実装紹介
Masahiro Sakai3.8K vistas
Introduction to Categorical Programming (Revised) por Masahiro Sakai
Introduction to Categorical Programming (Revised)Introduction to Categorical Programming (Revised)
Introduction to Categorical Programming (Revised)
Masahiro Sakai6.4K vistas
Haskell勉強会 14.1〜14.3 の説明資料 por Etsuji Nakai
Haskell勉強会 14.1〜14.3 の説明資料Haskell勉強会 14.1〜14.3 の説明資料
Haskell勉強会 14.1〜14.3 の説明資料
Etsuji Nakai2.5K vistas
Scala 初心者が米田の補題を Scala で考えてみた por Kazuyuki TAKASE
Scala 初心者が米田の補題を Scala で考えてみたScala 初心者が米田の補題を Scala で考えてみた
Scala 初心者が米田の補題を Scala で考えてみた
Kazuyuki TAKASE5.7K vistas
Introduction to Categorical Programming por Masahiro Sakai
Introduction to Categorical ProgrammingIntroduction to Categorical Programming
Introduction to Categorical Programming
Masahiro Sakai1.7K vistas
Halide による画像処理プログラミング入門 por Fixstars Corporation
Halide による画像処理プログラミング入門Halide による画像処理プログラミング入門
Halide による画像処理プログラミング入門
Fixstars Corporation15.5K vistas
Common LispでGPGPU por gos-k
Common LispでGPGPUCommon LispでGPGPU
Common LispでGPGPU
gos-k1.1K vistas
3次元図形をSchemeで造ろう! por vi-iv
3次元図形をSchemeで造ろう!3次元図形をSchemeで造ろう!
3次元図形をSchemeで造ろう!
vi-iv492 vistas
diffの真髄 por fuku68
diffの真髄diffの真髄
diffの真髄
fuku68928 vistas
すごいHaskell楽しく学ぼう-第12章モノイド- por Hiromasa Ohashi
すごいHaskell楽しく学ぼう-第12章モノイド-すごいHaskell楽しく学ぼう-第12章モノイド-
すごいHaskell楽しく学ぼう-第12章モノイド-
Hiromasa Ohashi1.6K vistas

Último

今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20... por
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...NTT DATA Technology & Innovation
73 vistas42 diapositivas
Windows 11 information that can be used at the development site por
Windows 11 information that can be used at the development siteWindows 11 information that can be used at the development site
Windows 11 information that can be used at the development siteAtomu Hidaka
71 vistas41 diapositivas
JJUG CCC.pptx por
JJUG CCC.pptxJJUG CCC.pptx
JJUG CCC.pptxKanta Sasaki
6 vistas14 diapositivas
Web3 Career_クレデン資料 .pdf por
Web3 Career_クレデン資料 .pdfWeb3 Career_クレデン資料 .pdf
Web3 Career_クレデン資料 .pdfnanamatsuo
14 vistas9 diapositivas
SNMPセキュリティ超入門 por
SNMPセキュリティ超入門SNMPセキュリティ超入門
SNMPセキュリティ超入門mkoda
175 vistas15 diapositivas
The Things Stack説明資料 by The Things Industries por
The Things Stack説明資料 by The Things IndustriesThe Things Stack説明資料 by The Things Industries
The Things Stack説明資料 by The Things IndustriesCRI Japan, Inc.
41 vistas29 diapositivas

Último(11)

今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20... por NTT DATA Technology & Innovation
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
Windows 11 information that can be used at the development site por Atomu Hidaka
Windows 11 information that can be used at the development siteWindows 11 information that can be used at the development site
Windows 11 information that can be used at the development site
Atomu Hidaka71 vistas
Web3 Career_クレデン資料 .pdf por nanamatsuo
Web3 Career_クレデン資料 .pdfWeb3 Career_クレデン資料 .pdf
Web3 Career_クレデン資料 .pdf
nanamatsuo14 vistas
SNMPセキュリティ超入門 por mkoda
SNMPセキュリティ超入門SNMPセキュリティ超入門
SNMPセキュリティ超入門
mkoda175 vistas
The Things Stack説明資料 by The Things Industries por CRI Japan, Inc.
The Things Stack説明資料 by The Things IndustriesThe Things Stack説明資料 by The Things Industries
The Things Stack説明資料 by The Things Industries
CRI Japan, Inc.41 vistas
「概念モデリング自動化に向けた第一歩」 ~ ChatGPT・Open AI 活用による開発対象のモデル化 por Knowledge & Experience
「概念モデリング自動化に向けた第一歩」 ~ ChatGPT・Open AI 活用による開発対象のモデル化「概念モデリング自動化に向けた第一歩」 ~ ChatGPT・Open AI 活用による開発対象のモデル化
「概念モデリング自動化に向けた第一歩」 ~ ChatGPT・Open AI 活用による開発対象のモデル化
SSH応用編_20231129.pdf por icebreaker4
SSH応用編_20231129.pdfSSH応用編_20231129.pdf
SSH応用編_20231129.pdf
icebreaker4172 vistas
01Booster Studio ご紹介資料 por ssusere7a2172
01Booster Studio ご紹介資料01Booster Studio ご紹介資料
01Booster Studio ご紹介資料
ssusere7a2172300 vistas
さくらのひやおろし2023 por 法林浩之
さくらのひやおろし2023さくらのひやおろし2023
さくらのひやおろし2023
法林浩之91 vistas
速習! PostgreSQL専用HAソフトウェア: Patroni(PostgreSQL Conference Japan 2023 発表資料) por NTT DATA Technology & Innovation
速習! PostgreSQL専用HAソフトウェア: Patroni(PostgreSQL Conference Japan 2023 発表資料)速習! PostgreSQL専用HAソフトウェア: Patroni(PostgreSQL Conference Japan 2023 発表資料)
速習! PostgreSQL専用HAソフトウェア: Patroni(PostgreSQL Conference Japan 2023 発表資料)

SICP

  • 1. SICP 二章 2013年 7月 2.1.1-2.1.4
  • 2. Cons(truct) (define x (cons 1 2)) car cdr 高階層化可能 (car (cdr z )) (Car x ) : 1 (Cdr x ) : 2
  • 4. ラムダ計算 非形式的な概説 (wiki) 例えば、ある数に 2 を加える関数 f を考える。これは通常の書き方では f(x) = x + 2 と書くことができるだろう。この関数 f は、ラムダ計算の式 (ラムダ式という)では λx. x + 2 と書かれる。変数 x の名前は重要では なく、 λy. y + 2 と書いても同じである。同様に、この関数に 3 を適用し た結果の数 f(3) は (λx. x + 2) 3 と書かれる。関数の適用は左結合である。 つまり、 f x y = (f x) y である。今度は、引数(関数の入力)に関数をとり それに 3 を適用する関数を考えてみよう。これはラムダ式では λf. f 3 と なる。この関数に、先ほど作った 2 を加える関数を適用すると、 (λf. f 3) (λx. x + 2) となる。ここで、 (λf. f 3) (λx. x + 2) と (λx. x + 2) 3 と 3 + 2 の3つの表現はいずれも同値である。
  • 5. Church数 (wikipedia) 0 ≡ λf.λx. X 1 ≡ λf.λx. f x 2 ≡ λf.λx. f (f x) 3 ≡ λf.λx. f (f (f x))... n ≡ λf.λx. fn x... 直感的には、数 n はラムダ式では f という関数 をもらってそれを n 回適用したものを返す関数 である。つまり、チャーチ数は1引数関数を受け 取り、1引数関数を返す高階関数である。
  • 6. Church数 ○n+1 n を受け取って n + 1 を返す関数を定 義することができる。 SUCC := λn f x. f (n f x)
  • 7. Church数 ○掛け算 m*n MULT := λm n. m (PLUS n) 0 この定義は、 m と n の乗算は、 0 に n を m回 加えることと等しい、ということを利用して 作られている。 MULT := λm n f. m (n f)
  • 8. 問 2.5 (define (print-point p) (newline) (display "(") (display (car p)) (display ",") (display (cdr p)) (display ")")) ; devide by 2 (define (getcar n) (getcar-iter n 0)) (define (getcar-iter n a) (if (= (remainder n 2) 0) (getcar-iter (/ n 2) (+ a 1)) a)) ; devide by 3 (define (getcdr n) (getcdr-iter n 0)) (define (getcdr-iter n b) (if (= (remainder n 3) 0) (getcdr-iter (/ n 3) (+ b 1)) b)) (define (get-num n ) (cons (getcar n) (getcdr n))) (define p (get-num 9)) (print-point p) コメント 赤字が追加部分 remainderのサブルーチンは共通化できるが未実施 (0,2)
  • 9. 問 2.6 ; n+1 (define (add1 n) (lambda (f) (lambda (x) (f ((n f) x))))) ;0 (define zero (lambda (f) (lambda (x) x))) ; 1= ramuda f x f x ;;;(print "cunning") ; from danboykis.com ;;;(add-1 zero) ;;;(add-1 (lambda (f) (lambda (x) x))) ;;;(lambda (f) (lambda (x) (f (((lambda (f) (lambda (x) x)) f) x)))) ;;;(lambda (f) (lambda (x) (f ((lambda (x) x) x)))) ;;;(lambda (f) (lambda (x) (f x))) (define one (lambda (f) (lambda (x) (f x )))) ;2 (define two (lambda (f) (lambda (x) (f(f x))))) ;3 (define three (lambda (f) (lambda (x) (f(f(f x))))))
  • 10. 問 2.6 その2 ;m+n (define (addc m n) (lambda (f) (lambda (x) ((m f) ((n f) x))))) ;;;;;;; verification (define (inc n) (+ n 1)) (print ((zero inc) 0)) (print ((one inc) 0)) (print ((two inc) 0)) (print ((three inc) 0)) (print (((add1 zero) inc) 0)) (print (((add1 one) inc) 0)) (define (bai n) (* n 2)) (print ((one bai) 1)) (print ((two bai) 1)) (print ((three bai) 1)) ;;;;; Question ;;;;;;; (print "1+3=") (print (((addc one three) inc) 0)) ;(print (((addc2 one three) inc) 0)) (print (((addc one three) bai) 1)) ;;;;; Question ;;;;; (print (((addc three three) bai) 1)) ;;;;; Question ;;;;;