<?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.3.4</title>
	<atom:link href="http://eli.thegreenplace.net/2007/07/19/sicp-section-134/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/</link>
	<description>Eli Bendersky's personal website</description>
	<pubDate>Thu, 04 Dec 2008 00:48:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: gorilych</title>
		<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-133138</link>
		<dc:creator>gorilych</dc:creator>
		<pubDate>Wed, 01 Oct 2008 10:40:16 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-133138</guid>
		<description>btw, we can use procedure accumulate from ex. 1.32 for ex. 1.43:

&lt;code&gt;
; 1.43

; we need compose from ex. 1.42:
(load "1.42.lisp")
; and accumulate from ex. 1.32:
(load "1.32.lisp")

(defun repeated (f n)
  (accumulate #'compose
              (lambda (x) x) ; identity function as a null-value
              (lambda (i) f)
              1
              #'1+
              n))
&lt;/code&gt;

Note that we already have 'accumulate' to produce iterative process.</description>
		<content:encoded><![CDATA[<p>btw, we can use procedure accumulate from ex. 1.32 for ex. 1.43:</p>
<p><code><br />
; 1.43</p>
<p>; we need compose from ex. 1.42:<br />
(load "1.42.lisp")<br />
; and accumulate from ex. 1.32:<br />
(load "1.32.lisp")</p>
<p>(defun repeated (f n)<br />
  (accumulate #'compose<br />
              (lambda (x) x) ; identity function as a null-value<br />
              (lambda (i) f)<br />
              1<br />
              #'1+<br />
              n))<br />
</code></p>
<p>Note that we already have &#8216;accumulate&#8217; to produce iterative process.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-132920</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Mon, 29 Sep 2008 12:03:07 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-132920</guid>
		<description>@gorilych
You're right - the word &lt;i&gt;iterative&lt;/i&gt; is confusing in this context, so I removed it.</description>
		<content:encoded><![CDATA[<p>@gorilych<br />
You&#8217;re right - the word <i>iterative</i> is confusing in this context, so I removed it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gorilych</title>
		<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-132917</link>
		<dc:creator>gorilych</dc:creator>
		<pubDate>Mon, 29 Sep 2008 09:58:32 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-132917</guid>
		<description>Your solution for ex. 1.43 produces recursive process, not iterative as you states.</description>
		<content:encoded><![CDATA[<p>Your solution for ex. 1.43 produces recursive process, not iterative as you states.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-98568</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Sun, 13 Jan 2008 19:19:43 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-98568</guid>
		<description>Sean, you're absolutely right - thanks for the tip!
I fixed the code in exercise 1.45</description>
		<content:encoded><![CDATA[<p>Sean, you&#8217;re absolutely right - thanks for the tip!<br />
I fixed the code in exercise 1.45</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-98508</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Sun, 13 Jan 2008 12:21:11 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-98508</guid>
		<description>I think your algorithm is bad for 1.45: repeated-dampen-root, repeatedly applies f as well as the average-damp.  You should only be repeating average-damp.

I investigated with

&lt;code&gt;
(define (try-ave-damp-root num-ave-damps n x)
  (fixed-point-of-transform (lambda (y) (/ x (expt y (-1+ n))))
			    (repeated average-damp num-ave-damps)
			    1.0))
&lt;/code&gt;

and found that (2^n)th root takes n average-damps.  I took tolerance down to 0.0000001 in my fixed-point test to stop some spurious convergences. This is on MIT/GNU Scheme 7.7.90.

So a solution is:

&lt;code&gt;
(define (log2 n)
  (if (= 1 n)
      0
      (1+ (log2 (floor (/ n 2))))))

(define (nth-root n x)
  (fixed-point-of-transform (lambda (y) (/ x (expt y (-1+ n))))
			    (repeated average-damp (log2 n))
			    1.0))
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I think your algorithm is bad for 1.45: repeated-dampen-root, repeatedly applies f as well as the average-damp.  You should only be repeating average-damp.</p>
<p>I investigated with</p>
<p><code><br />
(define (try-ave-damp-root num-ave-damps n x)<br />
  (fixed-point-of-transform (lambda (y) (/ x (expt y (-1+ n))))<br />
			    (repeated average-damp num-ave-damps)<br />
			    1.0))<br />
</code></p>
<p>and found that (2^n)th root takes n average-damps.  I took tolerance down to 0.0000001 in my fixed-point test to stop some spurious convergences. This is on MIT/GNU Scheme 7.7.90.</p>
<p>So a solution is:</p>
<p><code><br />
(define (log2 n)<br />
  (if (= 1 n)<br />
      0<br />
      (1+ (log2 (floor (/ n 2))))))</p>
<p>(define (nth-root n x)<br />
  (fixed-point-of-transform (lambda (y) (/ x (expt y (-1+ n))))<br />
			    (repeated average-damp (log2 n))<br />
			    1.0))<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-93363</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Wed, 19 Dec 2007 17:03:57 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-93363</guid>
		<description>For 1.45, I couldn't find a relationship between n (the root magnitude) and the number of times that damping should be applied either.</description>
		<content:encoded><![CDATA[<p>For 1.45, I couldn&#8217;t find a relationship between n (the root magnitude) and the number of times that damping should be applied either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-60542</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Thu, 19 Jul 2007 15:10:29 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-60542</guid>
		<description>I see you also had trouble with ex. 1.45, right?</description>
		<content:encoded><![CDATA[<p>I see you also had trouble with ex. 1.45, right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken Dyck</title>
		<link>http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-60526</link>
		<dc:creator>Ken Dyck</dc:creator>
		<pubDate>Thu, 19 Jul 2007 11:30:13 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/07/19/sicp-section-134/#comment-60526</guid>
		<description>Yikes! He's catching up. I'd better get a move on. ;)</description>
		<content:encoded><![CDATA[<p>Yikes! He&#8217;s catching up. I&#8217;d better get a move on. <img src='http://eli.thegreenplace.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
