From ac591ff0300586eda70b59d68993e79c1588a433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=B5=AA=E7=86=8A=E7=8C=AB=E5=84=BF?= Date: Wed, 28 Feb 2024 06:05:13 +0000 Subject: [PATCH] =?UTF-8?q?SICP=2003:=20=E9=80=92=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SICP/slide03.tm | 412 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 361 insertions(+), 51 deletions(-) diff --git a/SICP/slide03.tm b/SICP/slide03.tm index 29db6da..8203d1f 100644 --- a/SICP/slide03.tm +++ b/SICP/slide03.tm @@ -1,6 +1,6 @@ -> +> <\body> <\hide-preamble> @@ -57,7 +57,359 @@ Tree Recursion >>> - > + |<\hidden> + \<#4EF6\>\<#8868\>\<#8FBE\>\<#5F0F\>\<#548C\>\<#8C13\>\<#8BCD\>\V\<#77ED\>\<#8DEF\>\<#8FD0\>\<#7B97\>> + + <\itemize> + \<#5E94\>\<#7528\>\<#5E8F\>\<#6C42\>\<#503C\>\<#FF08\>Scheme\<#4F7F\>\<#7528\>\<#7684\>\<#662F\>\<#5E94\>\<#7528\>\<#5E8F\>\<#6C42\>\<#503C\>\<#FF09\> + + \<#6B63\>\<#5219\>\<#5E8F\>\<#6C42\>\<#503C\> + + + \<#4F8B\>\<#5206\>\<#6790\>\<#FF1A\>\<#5B9E\>\<#73B0\>\<#6C42\>\<#7EDD\>\<#5BF9\>\<#503C\>\<#7684\>\<#591A\>\<#79CD\>\<#65B9\>\<#5F0F\>> + + <\with|par-columns|2> + <\equation*> + =||||>|0,>>||>|>||>|0.>>>>>|\> + + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (define (abs1 x) + + \ \ (cond ((\ x 0) x) + + \ \ \ \ \ \ \ \ ((= x 0) 0) + + \ \ \ \ \ \ \ \ (else (- x)))) + <|unfolded-io> + abs1 + + + <\unfolded-io|Scheme] > + (define (abs2 x) + + \ \ (if (\ x 0) + + \ \ \ \ \ \ x + + \ \ \ \ \ \ (- x))) + <|unfolded-io> + abs2 + + + <\unfolded-io|Scheme] > + (define (abs3 x) + + \ \ (or (and (\ x) x) (- x))) + <|unfolded-io> + abs3 + + + <\unfolded-io|Scheme] > + (abs1 1) + <|unfolded-io> + 1 + + + <\unfolded-io|Scheme] > + (abs1 -1) + <|unfolded-io> + 1 + + + <\input|Scheme] > + \; + + + + + <\folded> + <\question> + \<#4E3A\>\<#4EC0\>\<#4E48\>\<#548C\>\<#662F\>\<#5FC5\>\<#987B\>\<#7684\>\<#FF1F\> + + <|folded> + <\exercise> + \<#4F7F\>\<#7528\>\<#5B9E\>\<#73B0\>\<#548C\>\<#3002\> + + + \<#53C2\>\<#8003\>\<#6587\>\<#6863\>\<#FF1A\> + + + \; + |<\hidden> + \<#73AF\>\<#FF1A\>\<#6C42\>\<#548C\>> + + \<#4F8B\>\<#5206\>\<#6790\>\<#FF1A\>\<#6C42\>\<#548C\>> + + <\with|par-columns|2> + <\equation*> + i=1+2+\+n + + + \; + + <\render-code> + result := 0 + + 1 n|result := result + i> + + + + + + <\with|par-columns|2> + <\session|scheme|default> + <\folded-io|Scheme] > + (define result 0) + <|folded-io> + 0 + + + <\input|Scheme] > + (for (x (list 1 2 3 4)) + + \ \ (set! result (+ result x))) + + + <\folded-io|Scheme] > + result + <|folded-io> + 10 + + + <\input|Scheme] > + \; + + + + <\session|python|default> + <\input> + \\\\ + <|input> + def sum_n(n): + + \ \ \ \ result= 0 + + \ \ \ \ for i in range(n): + + \ \ \ \ \ \ \ \ result= result + (i + 1) + + \ \ \ \ return result + + + <\folded-io> + \\\\ + <|folded-io> + sum_n(3) + <|folded-io> + 6 + + + <\folded-io> + \\\\ + <|folded-io> + list(range(3)) + <|folded-io> + [0, 1, 2] + + + <\input> + \\\\ + <|input> + \; + + + + + <\exercise> + \<#4F7F\>\<#7528\>Scheme\<#5B9E\>\<#73B0\>range\<#3002\> + + |<\hidden> + \<#6027\>\<#9012\>\<#5F52\>\<#FF1A\>\<#6C42\>\<#548C\>> + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (define (sum start end) + + \ \ (cond ((\ start end) 0) + + \ \ \ \ \ \ \ \ ((= start end) end) + + \ \ \ \ \ \ \ \ (else (+ start (sum (+ start 1) end))))) + + \; + <|unfolded-io> + sum + + + <\unfolded-io|Scheme] > + (sum 2 3) + <|unfolded-io> + 5 + + + <\input|Scheme] > + \; + + + + <\with|par-columns|2|par-left|1fn|par-right|4fn|par-columns-sep|0fn> + <\eqnarray*> + i>||i>>|||i|)>>>|||i|)>|)>>>|||>>|||+i|)>|)>>>>|||+|)>|)>>>|||+|)>|)>>>|||>>|||>|||>>> + + + + \; + |<\hidden> + \<#5F62\>\<#9012\>\<#5F52\>\<#FF1A\>\<#6590\>\<#6CE2\>\<#90A3\>\<#5951\>\<#6570\>\<#5217\>> + + <\folded> + <\equation*> + =||| + n=0,>>|| + n=1,>>|+>|.>>>>>|\> + + <|folded> + + |>>||>>||>>> + > + + + <\session|scheme|default> + <\folded-io|Scheme] > + (define (fib n) + + \ \ (cond ((= n 0) 0) + + \ \ \ \ \ \ \ \ ((= n 1) 1) + + \ \ \ \ \ \ \ \ (else (+ (fib (- n 1)) (fib (- n 2)))))) + <|folded-io> + fib + + + <\folded-io|Scheme] > + (fib 2) + <|folded-io> + 1 + + + <\input|Scheme] > + \; + + + |<\hidden> + \<#5F62\>\<#9012\>\<#5F52\>\\<#8FED\>\<#4EE3\>> + + <\equation*> + =||| + n=0,>>|| + n=1,>>|+>|.>>>>>|\> + + + <\equation*> + ||||||>|||>|||||||>|>|>|+f>>|=0>|=1>||||||||>||=1>|=2>|||||||>|||=2>|=3>||||||>||||=b>|=a+b>|||||>>>> + + + <\with|par-columns|2> + <\algorithm> + <\math> + a\ 0 + + b \ 1 + + <\algo-for|i \ 1 n> + a \ b + + b \ a + b + + + b + + + + <\algorithm> + a \ 0 + + b > 1 + + <\algo-for|i \ 1 n> + old_b \ b + + b \ a + b + + a \ old_b + + + b + + + + \; + |<\hidden> + \<#6CBB\>\<#6CD5\>\<#FF1A\>\<#627E\>\<#96F6\>\<#95EE\>\<#9898\>> + + <\itemize> + \<#65E0\>\<#9650\>\<#591A\>\<#4E00\>\<#5143\>\<#7EB8\>\<#5E01\> + + \<#65E0\>\<#9650\>\<#591A\>\<#4E94\>\<#5143\>\<#7EB8\>\<#5E01\> + + \<#65E0\>\<#9650\>\<#591A\>\<#5341\>\<#5143\>\<#7EB8\>\<#5E01\> + + \<#65E0\>\<#9650\>\<#591A\>\<#4E94\>\<#5341\>\<#5143\>\<#7EB8\>\<#5E01\> + + + <\folded-documentation> + <\question> + \6\<#6709\>\<#51E0\>\<#79CD\>\<#627E\>\<#96F6\>\<#65B9\>\<#5F0F\>\<#FF1F\> + + <|folded-documentation> + \6=6\\1, \6=1\\5+1 + + + <\folded-documentation> + <\question> + \16\<#6709\>\<#51E0\>\<#79CD\>\<#627E\>\<#96F6\>\<#65B9\>\<#5F0F\>\<#FF1F\> + + <|folded-documentation> + \; + + + <\folded-documentation> + <\question> + \<#5BF9\>\<#4E8E\>\n\<#FF0C\>\<#4E00\>\<#5171\>\<#6709\>\<#591A\>\<#5C11\>\<#79CD\>\<#627E\>\<#96F6\>\<#65B9\>\<#5F0F\>\<#FF1F\> + + <|folded-documentation> + <\equation*> + f|)>=f|)>+f|)>+f|)>+f|)>+f|)>+f|)>+f|)>+f|)>+f|)>+f|)>+f|)>+f|)>+f|)>+f|)> + + + <\equation*> + f|)>=f|)>+f|)> + + + |<\hidden> + \<#7ED3\>> + + <\itemize> + \<#56DE\>\<#987E\>\<#5E94\>\<#7528\>\<#5E8F\>\<#6C42\>\<#503C\>\<#548C\>\<#6B63\>\<#5219\>\<#5E8F\>\<#6C42\>\<#503C\> + + \<#6DF1\>\<#5165\>\<#7406\>\<#89E3\>\<#548C\> + + \<#7F16\>\<#7A0B\>\<#4E2D\>\<#6700\>\<#57FA\>\<#7840\>\<#7684\>\<#6982\>\<#5FF5\>\<#4E4B\>\<#4E00\>\<#FF1A\>\<#5FAA\>\<#73AF\> + + \<#4F7F\>\<#7528\>\<#9012\>\<#5F52\>\<#5B9E\>\<#73B0\>\<#5FAA\>\<#73AF\>\<#FF0C\>\<#57FA\>\<#4E8E\>\<#5FAA\>\<#73AF\>\<#7406\>\<#89E3\>\<#9012\>\<#5F52\> + + \<#5B9E\>\<#6218\>\<#FF1A\>\<#7EBF\>\<#6027\>\<#9012\>\<#5F52\>\<#548C\>\<#6811\>\<#5F62\>\<#9012\>\<#5F52\> + + \<#6280\>\<#5DE7\>\<#FF1A\>\<#5C06\>\<#9012\>\<#5F52\>\<#5B9E\>\<#73B0\>\<#6539\>\<#4E3A\>\<#8FED\>\<#4EE3\>\<#5B9E\>\<#73B0\> + + \<#62BD\>\<#8C61\>\<#FF1A\>\<#5229\>\<#7528\>\<#9012\>\<#5F52\>\<#89E3\>\<#51B3\>\<#73B0\>\<#5B9E\>\<#4E2D\>\<#7684\>\<#627E\>\<#96F6\>\<#95EE\>\<#9898\> + + > <\initial> @@ -66,70 +418,28 @@ + <\references> <\collection> - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > + > + > <\auxiliary> <\collection> - <\associate|figure> - |1>||\<#64CD\>\<#4F5C\>\<#7B26\>\<#548C\>\<#64CD\>\<#4F5C\>\<#6570\>>|> - - |2>||\<#4E00\>\<#4E2A\>\<#5177\>\<#4F53\>\<#7684\>\<#4F8B\>\<#5B50\>>|> - - <\associate|gly> - \<#8BED\>|> - - \<#8FBE\>\<#5F0F\>|> - - \<#6570\>|> - - \<#5408\>|> - - \<#8C61\>|> - - \<#5408\>\<#5F0F\>|> - - \<#5408\>\<#51FD\>\<#6570\>|> - - \<#6362\>\<#6A21\>\<#578B\>|> - - \<#7528\>\<#5E8F\>\<#6C42\>\<#503C\>|> - - \<#5219\>\<#5E8F\>\<#6C42\>\<#503C\>|> - <\associate|toc> - |\<#5E94\>\<#7528\>\<#5E8F\>\<#6C42\>\<#503C\> + |\<#6848\>\<#4F8B\>\<#5206\>\<#6790\>\<#FF1A\>\<#5B9E\>\<#73B0\>\<#6C42\>\<#7EDD\>\<#5BF9\>\<#503C\>\<#7684\>\<#591A\>\<#79CD\>\<#65B9\>\<#5F0F\> |.>>>>|> - > + > - |\<#6B63\>\<#5219\>\<#5E8F\>\<#6C42\>\<#503C\> + |\<#6848\>\<#4F8B\>\<#5206\>\<#6790\>\<#FF1A\>\<#6C42\>\<#548C\> |.>>>>|> - > - - |math-font-series||\<#672F\>\<#8BED\>\<#8868\>> - |.>>>>|> - + > \ No newline at end of file