<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: SICP section 1.2.3</title>
	<atom:link href="http://eli.thegreenplace.net/2007/06/28/sicp-section-123/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net/2007/06/28/sicp-section-123/</link>
	<description>Eli Bendersky's personal website</description>
	<pubDate>Thu, 04 Dec 2008 02:23:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Thomas</title>
		<link>http://eli.thegreenplace.net/2007/06/28/sicp-section-123/#comment-124429</link>
		<dc:creator>Thomas</dc:creator>
		<pubDate>Wed, 23 Jul 2008 14:18:18 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/06/28/sicp-section-123/#comment-124429</guid>
		<description>Dear Eli,

I'm studying Exercise 1.14, and I wonder if it's true that &lt;code&gt;cc&lt;/code&gt; grows exponentially in number of steps.  I found that the number of steps can be computed by the &lt;code&gt;cc-steps&lt;/code&gt; procedure below.

&lt;code&gt;
(define (sigma m n fun)
  (define (iterate sum m n)
    (if (&#60; n m)
        sum
        (iterate (+ sum (fun n)) m (- n 1))))
  (iterate 0 m (floor n)))
&lt;/code&gt;

&lt;code&gt;
(define (cc-steps amount kinds-of-coins)
  (if (= kinds-of-coins 1)
      (+ 1 (* amount 2))
      (+ 1
         (ceiling (/ amount (first-denomination kinds-of-coins)))
         (sigma 1
                (ceiling (/ amount (first-denomination kinds-of-coins)))
                (lambda (k)
                  (cc-steps
                   (- amount (* (first-denomination kinds-of-coins)
                                (- k 1)))
                   (- kinds-of-coins 1)))))))
&lt;/code&gt;

This amounts to nested summations, one fewer than the number of kinds of coins; so with five kinds of coins, there are four summations.  This is how it looks expanded out in Maxima code:

&lt;code&gt;
f(x) := (1
         + ceiling(x/50)
         + sum(1
               + ceiling((x-50*(i-1))/25)
               + sum(1
                     + ceiling((x-50*(i-1)-25*(j-1))/10)
                     + sum(1
                           + ceiling((x-50*(i-1)-25*(j-1)-10*(k-1))/5)
                           + sum(1
                                 + 2*(x-50*(i-1)-25*(j-1)-10*(k-1)-5*(l-1)),
                                 l,
                                 1,
                                 ceiling((x-50*(i-1)-25*(j-1)-10*(k-1))/5)),
                           k,
                           1,
                           ceiling((x-50*(i-1)-25*(j-1))/10)),
                     j,
                     1,
                     ceiling((x-50*(i-1))/25)),
               i,
               1,
               ceiling(x/50)));
&lt;/code&gt;

&lt;code&gt;X&lt;/code&gt; is in the term of the innermost summation and also in the upper bound, so ignoring everything but &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt; is added &lt;code&gt;x&lt;/code&gt; times, which is &lt;code&gt;x^2&lt;/code&gt;.  All four summations then result in &lt;code&gt;x^5&lt;/code&gt;, or &lt;code&gt;x&lt;/code&gt; to the power of the number of kinds of coins.  This is polynomial growth.

I plotted &lt;code&gt;x^5&lt;/code&gt; against &lt;code&gt;cc-steps&lt;/code&gt; with &lt;code&gt;x&lt;/code&gt; from 0 to 100, from 0 to 500, and from 0 to 1000, and found that the curves matched more closely each time (I can send you JPEGs if you send me your email address).

Please let me know if you see I'm making a mistake somewhere, and thanks for this great blog!

Thomas</description>
		<content:encoded><![CDATA[<p>Dear Eli,</p>
<p>I&#8217;m studying Exercise 1.14, and I wonder if it&#8217;s true that <code>cc</code> grows exponentially in number of steps.  I found that the number of steps can be computed by the <code>cc-steps</code> procedure below.</p>
<p><code><br />
(define (sigma m n fun)<br />
  (define (iterate sum m n)<br />
    (if (&lt; n m)<br />
        sum<br />
        (iterate (+ sum (fun n)) m (- n 1))))<br />
  (iterate 0 m (floor n)))<br />
</code></p>
<p><code><br />
(define (cc-steps amount kinds-of-coins)<br />
  (if (= kinds-of-coins 1)<br />
      (+ 1 (* amount 2))<br />
      (+ 1<br />
         (ceiling (/ amount (first-denomination kinds-of-coins)))<br />
         (sigma 1<br />
                (ceiling (/ amount (first-denomination kinds-of-coins)))<br />
                (lambda (k)<br />
                  (cc-steps<br />
                   (- amount (* (first-denomination kinds-of-coins)<br />
                                (- k 1)))<br />
                   (- kinds-of-coins 1)))))))<br />
</code></p>
<p>This amounts to nested summations, one fewer than the number of kinds of coins; so with five kinds of coins, there are four summations.  This is how it looks expanded out in Maxima code:</p>
<p><code><br />
f(x) := (1<br />
         + ceiling(x/50)<br />
         + sum(1<br />
               + ceiling((x-50*(i-1))/25)<br />
               + sum(1<br />
                     + ceiling((x-50*(i-1)-25*(j-1))/10)<br />
                     + sum(1<br />
                           + ceiling((x-50*(i-1)-25*(j-1)-10*(k-1))/5)<br />
                           + sum(1<br />
                                 + 2*(x-50*(i-1)-25*(j-1)-10*(k-1)-5*(l-1)),<br />
                                 l,<br />
                                 1,<br />
                                 ceiling((x-50*(i-1)-25*(j-1)-10*(k-1))/5)),<br />
                           k,<br />
                           1,<br />
                           ceiling((x-50*(i-1)-25*(j-1))/10)),<br />
                     j,<br />
                     1,<br />
                     ceiling((x-50*(i-1))/25)),<br />
               i,<br />
               1,<br />
               ceiling(x/50)));<br />
</code></p>
<p><code>X</code> is in the term of the innermost summation and also in the upper bound, so ignoring everything but <code>x</code>, <code>x</code> is added <code>x</code> times, which is <code>x^2</code>.  All four summations then result in <code>x^5</code>, or <code>x</code> to the power of the number of kinds of coins.  This is polynomial growth.</p>
<p>I plotted <code>x^5</code> against <code>cc-steps</code> with <code>x</code> from 0 to 100, from 0 to 500, and from 0 to 1000, and found that the curves matched more closely each time (I can send you JPEGs if you send me your email address).</p>
<p>Please let me know if you see I&#8217;m making a mistake somewhere, and thanks for this great blog!</p>
<p>Thomas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2007/06/28/sicp-section-123/#comment-121647</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Mon, 26 May 2008 15:39:32 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/06/28/sicp-section-123/#comment-121647</guid>
		<description>liwei:
Thanks for noticing. I've fixed the typo</description>
		<content:encoded><![CDATA[<p>liwei:<br />
Thanks for noticing. I&#8217;ve fixed the typo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: liwei</title>
		<link>http://eli.thegreenplace.net/2007/06/28/sicp-section-123/#comment-121646</link>
		<dc:creator>liwei</dc:creator>
		<pubDate>Mon, 26 May 2008 14:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/06/28/sicp-section-123/#comment-121646</guid>
		<description>"Clearly, p is called for as long as the division of the angle by 3 stays above 1.0;"

0.1</description>
		<content:encoded><![CDATA[<p>&#8220;Clearly, p is called for as long as the division of the angle by 3 stays above 1.0;&#8221;</p>
<p>0.1</p>
]]></content:encoded>
	</item>
</channel>
</rss>
