2014年1月8日水曜日

開発環境

計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の5(レジスタ計算機での計算)、5.5(翻訳系)、翻訳系の概観、5.5.7(翻訳したコードと評価器のインターフェース)、解釈と翻訳、問題 5.45-a.を解いてみる。

その他参考書籍

問題 5.45-a.

問題5.27問題5.14

コード(BBEdit)

sample.scm

(compile-and-go
'(define (factorial n)
   (if (= n 1)
       1
       (* (factorial (- n 1)) n))))

入出力結果(Terminal, REPL(Read, Eval, Print, Loop))

$ scheme
MIT/GNU Scheme running under MacOSX
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2011 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Saturday October 26, 2013 at 11:02:50 PM
  Release 9.1.1 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/C 4.118
  Edwin 3.116

1 ]=> (load "./eceval.scm")

;Loading "./eceval.scm"... done
;Value: start-eceval

1 ]=> (load "./sample.scm")

;Loading "./sample.scm"...
(total-pushes = 0 maximum-depth = 0)
;;; EC-Eval value:
ok

;;; EC-Eval input:
(factorial 1)

(total-pushes = 7 maximum-depth = 3)
;;; EC-Eval value:
1

;;; EC-Eval input:
(factorial 2)

(total-pushes = 13 maximum-depth = 5)
;;; EC-Eval value:
2

;;; EC-Eval input:
(factorial 3)

(total-pushes = 19 maximum-depth = 8)
;;; EC-Eval value:
6

;;; EC-Eval input:
(factorial 4)

(total-pushes = 25 maximum-depth = 11)
;;; EC-Eval value:
24

;;; EC-Eval input:
(factorial 5)

(total-pushes = 31 maximum-depth = 14)
;;; EC-Eval value:
120

;;; EC-Eval input:
End of input stream reached.
Moriturus te saluto.
$

factorial nについて。

翻訳版と解釈版について。

プッシュ回数とその比
n翻訳版解釈版
17160.4375
213480.2708
319800.2375
4251120.2232
5311440.2152
10613040.2006
5030115840.1900
10060131840.1887
5003001159840.1877
10006001319840.1876
5000300011599840.1875
10000600013199840.1875

近づく定数は約0.1875。

最大スタック深さとその比
n翻訳版解釈版
1331
2580.625
38130.6153
411180.6111
514230.6666
1029530.5471
501492530.5889
1002995030.5944
500149925030.5988
1000299950030.5994
500014999250030.5998
1000029999500030.5999

近づく定数は約0.6。

特殊目的の計算機と解釈版について。

プッシュ回数とその比
n特殊目的解釈版
10160
22480.0415
34800.05
461120.0535
581440.0555
10183040.5921
509815840.0618
10019831840.0621
500998159840.0624
10001998319840.0624
500099981599840.0624
10000199983199840.0624
最大スタック深さとその比
n特殊目的解釈版
1030
2280.25
34130.3076
46180.333
58230.3478
1018530.1509
50982530.3873
1001985030.3936
50099825030.3987
1000199850030.3993
50009998250030.3998
1000019998500030.3999

特殊目的のコード対解釈されるコードの比と、翻訳するコード対解釈されるコードの比について。

プッシュ回数とその比
特殊/解釈翻訳/解釈
0.06240.18750.3326
最大スタックの深さとその比
特殊/解釈翻訳/解釈
0.40.60.6666

問題の通り、特殊目的計算機は、翻訳したコードよりも遥かに優れていることが分かる。

0 コメント:

コメントを投稿