正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 4.3.5 Using different processes for the same goal Given that idea, here is the start of our procedure for my- expt. Notice how it recursively uses my-expt to solve Assume that the procedure my-expt exists, but only solves smaller versions of the same problem the subproblem, then multiplies the result by a to get the full Decompose problem into solving smaller version and using solution (lambda (a b) ( a (my-expt a (-b 1))))) 6001s Using different processes for the same goal Slide 4.3.6 Of course. as stated. that procedure will fail. as it will recurs Identify smallest size subproblem a0=1 Here, that is easy. Anything to the Oth power is just lep o indefinitely. To stop unwinding into simpler versions of th same problem, we need to find a smallest size subprob 6001 SICP Slide 4.3.7 Using different processes for the same goal And thus we can add our base case to our procedure, creating the same kind of procedure we saw earlier for factorial Identify smallest size subproblem Note how the base case will stop unwinding the computation into simpler cases (lambda (a b) ( a(rmy-expt a(-b 1)))) 60015e6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 4.3.5 Given that idea, here is the start of our procedure for my￾expt. Notice how it recursively uses my-expt to solve the subproblem, then multiplies the result by a to get the full solution. Slide 4.3.6 Of course, as stated, that procedure will fail, as it will recurse indefinitely. To stop unwinding into simpler versions of the same problem, we need to find a smallest size subproblem. Here, that is easy. Anything to the 0th power is just 1! Slide 4.3.7 And thus we can add our base case to our procedure, creating the same kind of procedure we saw earlier for factorial. Note how the base case will stop unwinding the computation into simpler cases
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有