From f407cadd06152a098cc074bff822663af9764b10 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Fri, 15 Mar 2024 13:14:10 +0800 Subject: [PATCH] SICP 05: final --- SICP/slide05.tm | 167 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 159 insertions(+), 8 deletions(-) diff --git a/SICP/slide05.tm b/SICP/slide05.tm index 7cea01d..48863fa 100644 --- a/SICP/slide05.tm +++ b/SICP/slide05.tm @@ -102,8 +102,7 @@ \<#6CD5\>\<#5BFC\>\<#8BBA\>\<#5BF9\>>\<#8BB0\>\<#53F7\>\<#7684\>\<#5B9A\>\<#4E49\>> <\definition> - For a given function >, we denote by |)>> + \<#5BF9\>\<#4E8E\>\<#7ED9\>\<#5B9A\>\<#7684\>\<#51FD\>\<#6570\>>\<#FF0C\>\<#6211\>\<#4EEC\>\<#4F7F\>\<#7528\>\<#8BB0\>\<#6CD5\>|)>>\<#8868\>\<#793A\>\<#4E00\>\<#7EC4\>\<#51FD\>\<#6570\>\<#7684\>\<#96C6\>\<#5408\>\<#FF1A\> <\equation*> \|)>=: @@ -112,8 +111,7 @@ <\definition> - For a given function >, we denote the set of - funtions by |)>> + \<#5BF9\>\<#4E8E\>\<#7ED9\>\<#5B9A\>\<#7684\>\<#51FD\>\<#6570\>>\<#FF0C\>\<#6211\>\<#4EEC\>\<#4F7F\>\<#7528\>\<#8BB0\>\<#6CD5\>|)>>\<#8868\>\<#793A\>\<#4E00\>\<#7EC4\>\<#51FD\>\<#6570\>\<#7684\>\<#96C6\>\<#5408\>\<#FF1A\> <\equation*> O|)>=:\c,n,\n\n,0\f\c*g|}> @@ -121,8 +119,7 @@ <\definition> - For a given function , we denote the set of fuctions by - |)>> + \<#5BF9\>\<#4E8E\>\<#7ED9\>\<#5B9A\>\<#7684\>\<#51FD\>\<#6570\>\<#FF0C\>\<#6211\>\<#4EEC\>\<#4F7F\>\<#7528\>\<#8BB0\>\<#6CD5\>|)>>\<#8868\>\<#793A\>\<#4E00\>\<#7EC4\>\<#51FD\>\<#6570\>\<#7684\>\<#96C6\>\<#5408\>\<#FF1A\> <\equation*> \|)>=:\c,n,\n\n,0\c*g\f|}> @@ -263,13 +260,127 @@ <\slide> - \<#5E42\>> + \<#5E42\>\<#2014\>\<#2014\>\<#7EBF\>\<#6027\>\<#9012\>\<#5F52\>\<#7684\>\<#8BA1\>\<#7B97\>\<#8FC7\>\<#7A0B\>> <\equation*> b=b>|1>>|>|>>>> + <\session|scheme|default> + <\unfolded-io|Scheme] > + (define (expt-1 b n) + + \ \ (if (= n 0) + + \ \ \ \ \ \ 1 + + \ \ \ \ \ \ (* b (expt-1 b (- n 1))))) + <|unfolded-io> + expt-1 + + + <\unfolded-io|Scheme] > + (expt-1 1 0) + <|unfolded-io> + 1 + + + <\unfolded-io|Scheme] > + (expt-1 2 3) + <|unfolded-io> + 8 + + + + <\big-table|\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>>|>>>|\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>>|>>>>>>> + \<#590D\>\<#6742\>\<#5EA6\> + + + + <\slide> + \<#5E42\>\<#2014\>\<#2014\>\<#7EBF\>\<#6027\>\<#8FED\>\<#4EE3\>\<#7684\>\<#8BA1\>\<#7B97\>\<#8FC7\>\<#7A0B\>> + \; + + <\equation*> + b=b>|1>>|>|>>>> + + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (define (expt-2 b n) + + \ \ (define (expt-iter b counter product) + + \ \ \ \ (if (= counter 0) + + \ \ \ \ \ \ \ \ product + + \ \ \ \ \ \ \ \ (expt-iter b + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (- counter 1) + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (* b product)))) + + \ \ + + \ \ (expt-iter b n 1)) + <|unfolded-io> + expt-2 + + + <\unfolded-io|Scheme] > + (expt-2 3 3) + <|unfolded-io> + 27 + + + + <\big-table|\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>>|>>>|\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>>|>>>>>>> + \<#590D\>\<#6742\>\<#5EA6\> + + + + <\slide> + \<#5E42\>\<#2014\>\<#2014\>\<#4F18\>\<#5316\>\<#65B9\>\<#6848\>> + + \; + + <\equation*> + b=|)>>|\<#5076\>\<#6570\>>>|b>|\<#5947\>\<#6570\>>>>>> + + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (define (fast-expt b n) + + \ \ (define (even? n) + + \ \ \ \ (= (remainder n 2) 0)) + + \ \ (define (square x) (* x x)) + + \ \ + + \ \ (cond ((= n 0) 1) + + \ \ \ \ \ \ \ \ ((even? n) (square (fast-expt b (/ n 2)))) + + \ \ \ \ \ \ \ \ (else (* b (fast-expt b (- n 1)))))) + <|unfolded-io> + fast-expt + + + <\unfolded-io|Scheme] > + (fast-expt 3 3) + <|unfolded-io> + 27 + + + + <\big-table|\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>>||)>>>>|\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>>|>>>>>>> + \<#590D\>\<#6742\>\<#5EA6\> + <\slide> @@ -296,6 +407,38 @@ n|)>>\<#7684\>\<#8BC1\>\<#660E\>\<#3002\> + + <\slide> + \<#7ED3\>> + + <\itemize> + \<#672F\>\<#8BED\>\<#56DE\>\<#987E\>\<#FF1A\>\<#6B63\>\<#5219\>\<#662F\>\<#4E2A\>\<#4EC0\>\<#4E48\>\<#9B3C\> + + \<#65F6\>\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>\<#548C\>\<#7A7A\>\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>\<#7684\>\<#8BB0\>\<#53F7\> + + \<#56DE\>\<#987E\>\<#5728\>\<#7B2C\>\<#4E09\>\<#8BFE\>\<#63D0\>\<#5230\>\<#7684\>\<#51FD\>\<#6570\> + + \<#6C42\>>\<#7684\>\<#4E0D\>\<#540C\>\<#5B9E\>\<#73B0\>\<#7684\>\<#4E0D\>\<#540C\>\<#65F6\>\<#7A7A\>\<#590D\>\<#6742\>\<#5EA6\> + + \<#6709\>\<#4E00\>\<#4E9B\>\<#7B97\>\<#6CD5\>\<#7684\>\<#65F6\>\<#95F4\>\<#590D\>\<#6742\>\<#5EA6\>\<#5E76\>\<#4E0D\>\<#662F\>\<#663E\>\<#800C\>\<#6613\>\<#89C1\>\<#7684\>\<#FF0C\>\<#9700\>\<#8981\>\<#6570\>\<#5B66\>\<#53BB\>\<#8BC1\>\<#660E\> + + + \; + + \<#6590\>\<#6CE2\>\<#90A3\>\<#5951\>\<#6570\>\<#5217\>\<#7B2C\>n\<#9879\>\<#7684\>\<#8BA1\>\<#7B97\>\<#662F\>\<#4E00\>\<#4E2A\>\<#6811\>\<#5F62\>\<#9012\>\<#5F52\>\<#FF0C\>\<#5E76\>\<#4E0D\>\<#80FD\>\<#5F88\>\<#65B9\>\<#4FBF\>\<#5730\>\<#8F6C\>\<#6362\>\<#4E3A\>\<#7EBF\>\<#6027\>\<#8FED\>\<#4EE3\>\<#7684\>\<#8BA1\>\<#7B97\>\<#8FC7\>\<#7A0B\>\<#FF1A\> + + <\eqnarray*> + >||-\|)>|\>>>||>||\>>>>> + + + <\exercise> + \<#56DE\>\<#987E\>\<#8BA1\>\<#7B97\>\<#6590\>\<#6CE2\>\<#90A3\>\<#5951\>\<#6570\>\<#5217\>\<#7B2C\>n\<#9879\>\<#7684\>\<#4E0D\>\<#540C\>\<#65B9\>\<#6CD5\>\<#7684\>\<#65F6\>\<#7A7A\>\<#590D\>\<#6742\>\<#5EA6\>\<#3002\> + + + <\render-exercise|\<#601D\>\<#8003\>\<#9898\>> + \<#5728\>\<#6709\>\<#9650\>\<#7684\>\<#65F6\>\<#95F4\>\<#5185\>\<#FF0C\>\<#6BD4\>\<#5982\>1\<#5206\>\<#949F\>\<#FF0C\>\<#5F97\>\<#5230\>\<#80FD\>\<#591F\>\<#8BA1\>\<#7B97\>\<#51FA\>\<#6765\>\<#7684\>\<#6590\>\<#6CE2\>\<#90A3\>\<#5951\>\<#6570\>\<#5217\>\<#6700\>\<#5927\>\<#4E00\>\<#9879\>\<#3002\> + + @@ -311,4 +454,12 @@ - \ No newline at end of file + + +<\references> + <\collection> + > + > + > + + \ No newline at end of file