• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            CG@CPPBLOG

            /*=========================================*/
            隨筆 - 76, 文章 - 39, 評論 - 137, 引用 - 0
            數據加載中……

            我的SICP習題答案(1.16~1.19)

            1.16
            (define (fast-expt x n)
              (fast-expt-iter x n 
            1))

            (define (fast-expt-iter x n a)
              (cond ((
            = n 0) a)
                    ((even? n) (fast-expt-iter (square x) 
                                               (/ n 
            2)
                                               a))
                    (else (fast-expt-iter x 
                                          (- n 
            1)
                                          (* a x)))))

            1.17
            (define (multi x y)
              (if (
            = y 0)
                  
            0
                  (+ x (multi x (- y 
            1)))))

            (define (fast-multi x y)
              (cond ((
            = y 00)
                    ((even? y) (double (fast-multi x
                                           (half y))))
                    (else (+ x (fast-multi x (- y 
            1))))))

            (define (double x) (+ x x))
            (define (half y) (/ y 
            2))

            1.18
            (define (double x) (+ x x))
            (define (half y) (/ y 
            2))

            (define (fast-multi x y)
              (fast-multi-iter x y 
            0))

            (define (fast-multi-iter x y p)
              (cond ((
            = y 0) p)
                    ((even? y) (fast-multi-iter (double x)
                                                (half y)
                                                p))
                    (else (fast-multi-iter x (- y 
            1) (+ p x)))))

            1.19
            ;T(pq):(a,b)=>(bq+aq+ap, bp+aq)
            ;
            T(pq):(bq+aq+ap, bp+aq)=>((bp+aq)q + (bq+aq+ap)q + (bq+aq+ap)p,
            ;
                                      (bp+aq)p + (bq+aq+ap)q)
            ;
                  => (2bpq+2aqq+bqq+2apq+app, bpp+2apq+bqq+aqq)
            ;
                  => (b(2pq+qq)+a(2pq+qq)+a(qq+pp), b(qq+pp)+a(2pq+qq))
            ;
            q' = 2pq+qq
            ;
            p' = qq+pp
            ;
            (define (fib n)
              (fib-iter 
            1 0 0 1 n))

            (define (fib-iter a b p q count)
              (cond ((
            = count 0) b)
                    ((even? count) 
                     (fib-iter a
                               b
                               (+ (* p p) (* q q))
                               (+ (* 
            2 p q ) (* q q))
                               (/ count 
            2)))
                    (else (fib-iter (+ (* b q) (* a q) (* a p))
                                    (+ (* b p) (* a q))
                                    p
                                    q
                                    (- count 
            1)))))


            posted on 2008-03-27 00:53 cuigang 閱讀(834) 評論(1)  編輯 收藏 引用 所屬分類: Lisp/Scheme我的SICP答案

            評論

            # re: 我的SICP習題答案(1.16~1.19)[未登錄]  回復  更多評論   

            good~
            2008-07-19 10:21 | sun
            日本国产精品久久| 99久久人妻无码精品系列蜜桃| 香港aa三级久久三级| 久久强奷乱码老熟女| 精品久久久中文字幕人妻| 久久99精品久久只有精品| 久久免费线看线看| 亚洲欧美精品一区久久中文字幕| 久久国产免费直播| 办公室久久精品| 五月丁香综合激情六月久久| 办公室久久精品| 亚洲中文字幕无码一久久区| 国产国产成人久久精品| 无码人妻久久一区二区三区免费丨| 久久久久国产一级毛片高清版| 亚洲国产成人精品女人久久久| 99久久久精品免费观看国产| 亚洲欧美一级久久精品| 韩国无遮挡三级久久| 中文字幕日本人妻久久久免费| 国产精品青草久久久久福利99| 无码AV中文字幕久久专区| 99久久精品免费看国产| 9久久9久久精品| 亚洲AV无码久久| 久久乐国产综合亚洲精品| 久久精品国产72国产精福利| 亚洲狠狠综合久久| 国产精品九九九久久九九| 三上悠亚久久精品| 精品一二三区久久aaa片| 99久久香蕉国产线看观香| 亚洲а∨天堂久久精品| 亚洲国产成人久久一区久久| 久久精品国产清自在天天线| 91精品日韩人妻无码久久不卡| 成人国内精品久久久久影院VR| 久久99热精品| 九九久久精品国产| 人妻丰满?V无码久久不卡|