<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ken Dyck</title>
	<atom:link href="https://kendyck.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://kendyck.com</link>
	<description>An abandoned weblog</description>
	<lastBuildDate>Thu, 12 May 2016 11:40:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<site xmlns="com-wordpress:feed-additions:1">111067655</site><cloud domain='kendyck.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s0.wp.com/i/buttonw-com.png</url>
		<title>Ken Dyck</title>
		<link>https://kendyck.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://kendyck.com/osd.xml" title="Ken Dyck" />
	<atom:link rel='hub' href='https://kendyck.com/?pushpress=hub'/>
	<item>
		<title>Solution to SICP Exercise 2.13</title>
		<link>https://kendyck.com/2007/10/24/solution-to-sicp-exercise-213/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Wed, 24 Oct 2007 23:51:36 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/10/24/solution-to-sicp-exercise-213/</guid>

					<description><![CDATA[One solution to Exercise 2.13: In exercise 2.12, we found a way to express a range as a tolerance. (define (make-center-percent c p) (make-center-width c (* c (/ p 100)))) #1 Where, (define (make-center-width c w) (make-interval (- c w) (+ c w))) #2 Expanding #2 in #1 give us: (define (make-center-percent c p) (make-interval &#8230; <a href="https://kendyck.com/2007/10/24/solution-to-sicp-exercise-213/" class="more-link">Continue reading<span class="screen-reader-text"> "Solution to SICP Exercise&#160;2.13"</span></a>]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>One solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.13">Exercise 2.13</a>:</p>
<p>In exercise 2.12, we found a way to express a range as a tolerance.</p>
<p><code>(define (make-center-percent c p)<br />
  (make-center-width c (* c (/ p 100))))</code> #1</p>
<p>Where, </p>
<p><code>(define (make-center-width c w)<br />
  (make-interval (- c w) (+ c w)))</code> #2</p>
<p>Expanding #2 in #1 give us:</p>
<p><code>(define (make-center-percent c p)<br />
  (make-interval (- c (* c (/ p 100)))<br />
                 (+ c (* c (/ p 100)))))</code> #3</p>
<p>Now, imagine a range, <code>x</code> with a center <code>cx</code><br />
and a percentage tolerance <code>px</code>.</p>
<p><code>(define x (make-center-percent cx px))</code> #4</p>
<p>Expanding #4 out, from #3, we get:</p>
<p><code>(define x<br />
  (make-interval (- cx (* cx (/ px 100)))<br />
                 (+ cx (* cx (/ px 100)))))</code> #5</p>
<p>That&#8217;s a bit messy with all those divisions by 100. Let&#8217;s introduce<br />
an absolute tolerance, <code>tx</code>, that is one hundreth the<br />
size of the percentage tolerance.</p>
<p><code>(define px (* tx 100))</code> #6</p>
<p>Substituting #6 into #5, we get:</p>
<p><code>(define x<br />
  (make-interval (- cx (* cx tx))<br />
                 (+ cx (* cx tx))))</code> #7</p>
<p>We&#8217;ll need another range if we are to do any multiplication. Let&#8217;s<br />
likewise define <code>y</code>:</p>
<p><code>(define y<br />
  (make-interval (- cy (* cy ty))<br />
                 (+ cy (* cy ty))))</code> #8</p>
<p>Another lesson we learned from exercise 2.12 is how to find the<br />
width of a range:</p>
<p><code>(define (width i)<br />
  (/ (- (upper-bound i) (lower-bound i)) 2))</code> #9</p>
<p>A couple of relations that we are almost certain to find useful<br />
(and I hope you&#8217;ll find obvious):</p>
<p><code>(equal u (upper-bound (make-interval l u)))</code> #10<br />
<code>(equal l (lower-bound (make-interval l u)))</code> #11</p>
<p>In exercise 2.11, we found that when all the numbers are positive,<br />
we can define <code>mul-interval</code> as follows:</p>
<p><code>(define (mul-interval x y)<br />
  (make-interval (* (lower-bound x) (lower-bound y))<br />
                 (* (upper-bound x) (upper-bound y))))</code> #12</p>
<p>We are interested in the percentage tolerance of the product of two<br />
intervals in terms of their percentage tolerances. In other words,</p>
<p><code>(percent (mul-interval x y))</code> #13</p>
<p>You&#8217;ll recall the definition of <code>percent</code> from exercise<br />
2.12:</p>
<p><code>(define (percent i)<br />
  (* (/ (width i) (center i)) 100))</code> #14</p>
<p>Expanding #13 with #14, we get:</p>
<p><code>(* (/ (width (mul-interval x y))<br />
      (center (mul-interval x y)))<br />
   100)</code> #15</p>
<p>To keep things from getting too messy, let&#8217;s just focus on the<br />
<code>width</code> part for now:</p>
<p><code>(width (mul-interval x y))</code> #16</p>
<p>Substituting in #12</p>
<p><code>(width (make-interval<br />
         (* (lower-bound x)<br />
            (lower-bound y))<br />
         (* (upper-bound x)<br />
            (upper-bound y))))</code> #17</p>
<p>And the definitions of <code>x</code> and <code>y</code> from #7<br />
and #8:</p>
<p><code>(width (make-interval<br />
         (* (lower-bound (make-interval (- cx (* cx tx))<br />
                                        (+ cx (* cx tx))))<br />
            (lower-bound (make-interval (- cy (* cy ty))<br />
                                        (+ cy (* cy ty)))))<br />
         (* (upper-bound (make-interval (- cx (* cx tx))<br />
                                        (+ cx (* cx tx))))<br />
            (upper-bound (make-interval (- cy (* cy ty))<br />
                                        (+ cy (* cy ty)))))))</code> #18</p>
<p>Boy, this is getting messy. We can rely on relations #10 and #11 to<br />
tidy things up a bit.</p>
<p><code>(width (make-interval<br />
         (* (- cx (* cx tx))<br />
            (- cy (* cy ty)))<br />
         (* (+ cx (* cx tx))<br />
            (+ cy (* cy ty)))))</code> #19</p>
<p>Expanding out the products:</p>
<p><code>(width (make-interval<br />
         (- (+ (* cx cy) (* cx tx cy ty))<br />
            (+ (* cx cy ty) (* cy cx tx)))<br />
         (+ (* cx cy) (*cx tx cy ty)<br />
            (* cx cy ty) (* cy cx tx))))</code> #20</p>
<p>Substituting into #9</p>
<p><code>(/ (- (upper-bound<br />
        (make-interval<br />
          (- (+ (* cx cy) (* cx tx cy ty))<br />
             (+ (* cx cy ty) (* cy cx tx)))<br />
          (+ (* cx cy) (*cx tx cy ty)<br />
             (* cx cy ty) (* cy cx tx))))<br />
      (lower-bound<br />
        (make-interval<br />
          (- (+ (* cx cy) (* cx tx cy ty))<br />
             (+ (* cx cy ty) (* cy cx tx)))<br />
          (+ (* cx cy) (*cx tx cy ty)<br />
             (* cx cy ty) (* cy cx tx)))))<br />
   2)</code> #21</p>
<p>Another mess. But we can call on #10 and #11 again to clean things<br />
up.</p>
<p><code>(/ (- (+ (* cx cy) (*cx tx cy ty)<br />
         (* cx cy ty) (* cy cx tx))<br />
      (- (+ (* cx cy) (* cx tx cy ty))<br />
         (+ (* cx cy ty) (* cy cx tx))))<br />
   2)</code> #22</p>
<p>Let&#8217;s rearrange the terms to see what, if anything, cancels out.</p>
<p><code>(/ (+ (- (* cx cy) (* cx cy))<br />
      (- (*cx tx cy ty) (*cx tx cy ty))<br />
      (* cx cy ty) (* cx cy ty)<br />
      (* cy cx tx) (* cy cx tx))<br />
   2)</code> #23</p>
<p>Now we&#8217;re getting somewhere:</p>
<p><code>(/ (+ (* 2 cx cy ty)<br />
            (* 2 cy cx tx))<br />
         2)</code> #24</p>
<p>Simplifying.</p>
<p><code>(+ (* cx cy ty) (* cy cx tx)))</code> #25</p>
<p>And again.</p>
<p><code>(* cx cy (+ tx ty))</code> #26</p>
<p>So now we know what the <code>width</code> of a product is in terms<br />
of the tolerances and centers. Now let&#8217;s take a look at the<br />
<code>center</code> of a product.</p>
<p><code>(center (mul-interval x y))</code> #27</p>
<p>From exercise 2.12, we know the definiton of <code>center</code></p>
<p><code>(define (center i)<br />
  (/ (+ (lower-bound i) (upper-bound i)) 2))</code> #28</p>
<p>Expanding #27.</p>
<p><code>(/ (+ (lower-bound (mul-interval x y))<br />
      (upper-bound (mul-interval x y)))<br />
   2)</code> #29</p>
<p>Substituting #12.</p>
<p><code>(/ (+ (lower-bound (make-interval<br />
                     (* (lower-bound x) (lower-bound y))<br />
                     (* (upper-bound x) (upper-bound y))))<br />
      (upper-bound (make-interval<br />
                     (* (lower-bound x) (lower-bound y))<br />
                     (* (upper-bound x) (upper-bound y)))))<br />
   2)</code> #30</p>
<p>Using #10 and #11, again.</p>
<p><code>(/ (+ (* (lower-bound x) (lower-bound y))<br />
      (* (upper-bound x) (upper-bound y)))<br />
   2)</code> #31</p>
<p>Subsituting in #7 and #8:</p>
<p><code>(/ (+ (* (lower-bound (make-interval (- cx (* cx tx))<br />
                                     (+ cx (* cx tx))))<br />
         (lower-bound (make-interval (- cy (* cy ty))<br />
                                     (+ cy (* cy ty)))))<br />
      (* (upper-bound (make-interval (- cx (* cx tx))<br />
                                     (+ cx (* cx tx))))<br />
         (upper-bound (make-interval (- cy (* cy ty))<br />
                                     (+ cy (* cy ty))))))<br />
   2)</code> #32</p>
<p>Can&#8217;t get enough of #10 and #11:</p>
<p><code>(/ (+ (* (- cx (* cx tx))<br />
         (- cy (* cy ty)))<br />
      (* (+ cx (* cx tx))<br />
         (+ cy (* cy ty))))<br />
   2)</code> #33</p>
<p>Expanding it all out:</p>
<p><code>(/ (+ (- (* cx cy) (* cx cy ty))<br />
      (- (* cx tx cy ty) (* cy cx tx))<br />
      (* cx cy) (* cx cy ty)<br />
      (* cx tx cy ty) (* cy cx tx))<br />
   2)</code> #34</p>
<p>Several terms cancel out again, leaving:</p>
<p><code>(/ (+ (* 2 cx cy)<br />
      (* 2 cx tx cy ty))<br />
   2)</code> #35</p>
<p>Since we are assuming small tolerances, the second term<br />
<code>(* 2 cx tx cy ty)</code> is effectively zero, leaving us<br />
with:</p>
<p><code>(/ (* 2 cx cy)<br />
   2)</code> #36</p>
<p>Or,</p>
<p><code>(* cx cy)</code> #37</p>
<p>Now we can return to #15, substituting #26 and #37 in:</p>
<p><code>(* (/ (* cx cy (+ tx ty)))<br />
      (* cx cy))<br />
   100)</code> #38</p>
<p>This simplifies quite nicely to:</p>
<p><code>(* (+ tx ty) 100)</code> #39</p>
<p>Recall from #6 that we defined <code>tx</code> and <code>ty</code><br />
to eliminate the division by 100. If we switch back to percentage<br />
notation, now, we get rid of that pesky 100 for good:</p>
<p><code>(+ px py)</code> #40</p>
<p>There you have it. Assuming small tolerances, we can conclude that<br />
the percentage tolerance of the product of two intervals is equal<br />
to the sum of the tolerances of the multiplicands.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">875</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to SICP Exercise 2.12</title>
		<link>https://kendyck.com/2007/07/17/solution-to-sicp-exercise-212/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Tue, 17 Jul 2007 23:30:34 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/07/17/solution-to-sicp-exercise-212/</guid>

					<description><![CDATA[One solution to Exercise 2.12: (define (make-center-percent c p) (make-center-width c (* c (/ p 100)))) (define (percent i) (* (/ (width i) (center i)) 100))]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>One solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.12">Exercise 2.12</a>:</p>
<p><code>(define (make-center-percent c p)<br />
  (make-center-width c (* c (/ p 100))))</p>
<p>(define (percent i)<br />
  (* (/ (width i) (center i)) 100))<br />
</code></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">874</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to SICP Exercise 2.11</title>
		<link>https://kendyck.com/2007/07/16/solution-to-sicp-exercise-211/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Tue, 17 Jul 2007 00:30:08 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/07/16/solution-to-sicp-exercise-211/</guid>

					<description><![CDATA[One solution to Exercise 2.11: (define (mul-interval x y) (let* ((lx (lower-bound x)) (ux (upper-bound x)) (ly (lower-bound y)) (uy (upper-bound y)) (pos-lx? (positive? lx)) (pos-ux? (positive? ux)) (pos-ly? (positive? ly)) (pos-uy? (positive? uy))) (cond ; lx ux ly uy example ; ---------------------------------- ; + - + + invalid interval ; + - + - &#8230; <a href="https://kendyck.com/2007/07/16/solution-to-sicp-exercise-211/" class="more-link">Continue reading<span class="screen-reader-text"> "Solution to SICP Exercise&#160;2.11"</span></a>]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>One solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.11">Exercise 2.11</a>:</p>
<pre><code>(define (mul-interval x y)
(let* ((lx (lower-bound x))
(ux (upper-bound x))
(ly (lower-bound y))
(uy (upper-bound y))
(pos-lx? (positive? lx))
(pos-ux? (positive? ux))
(pos-ly? (positive? ly))
(pos-uy? (positive? uy)))
(cond
; lx ux ly uy example
; ----------------------------------
; + - + + invalid interval
; + - + - invalid interval
; + - - + invalid interval
; + - - - invalid interval
((and pos-lx? (not pos-ux?))
(error "invalid interval" x))

; + + + - invalid interval
; - + + - invalid interval
; - - + - invalid interval
((and pos-ly? (not pos-uy?))
(error "invalid interval" y))

; + + + + (1.2)(2.3) = (2.6)
((and pos-lx? pos-ux? pos-ly? pos-uy?)
(make-interval (* lx ly) (* ux uy)))

; + + - + (1.2)(-2.3) = (-4.6)
((and pos-lx? pos-ux? (not pos-ly?) pos-uy?)
(make-interval (* ux ly) (* ux uy)))

; + + - - (1.2)(-2.-1) = (-4.-1)
((and pos-lx? pos-ux? (not pos-ly?) (not pos-uy?))
(make-interval (* ux ly) (* lx uy)))

; - + + + (-1.2)(2.3) = (-3.6)
((and (not pos-lx?) pos-ux? pos-ly? pos-uy?)
(make-interval (* lx uy) (* ux uy)))

; - + - + (-1.2)(-2.3) = (-4.6) *
((and (not pos-lx?) pos-ux? (not pos-ly?) pos-uy?)
(make-interval (min (* lx uy) (* ux ly))
(* ux uy)))

; - + - - (-1.2)(-2.-1) = (-4.2)
((and (not pos-lx?) pos-ux? (not pos-ly?) (not pos-uy?))
(make-interval (* ux ly) (* lx ly)))

; - - + + (-2.-1)(2.3) = (-6.-2)
((and (not pos-lx?) (not pos-ux?) pos-ly? pos-uy?)
(make-interval (* lx uy) (* ux ly)))

; - - - + (-2.-1)(-2.3) = (-6, 4)
((and (not pos-lx?) (not pos-ux?) (not pos-ly?) pos-uy?)
(make-interval (* lx uy) (* lx ly)))

; - - - - (-2.-1)(-2.-1) = (1.4)
((and (not pos-lx?) (not pos-ux?) (not pos-ly?) (not pos-uy?))
(make-interval (* ux uy) (* lx ly))))))</code></pre>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">873</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to SICP Exercise 2.10</title>
		<link>https://kendyck.com/2007/07/15/solution-to-sicp-exercise-210/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Sun, 15 Jul 2007 18:34:06 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/07/15/solution-to-sicp-exercise-210/</guid>

					<description><![CDATA[One solution to Exercise 2.10: (define (spans-zero? x) (not (or (positive? (lower-bound x)) (negative? (upper-bound x))))) (define (div-interval x y) (if (spans-zero? y) (error "Divisor spans zero" y) (mul-interval x (make-interval (/ 1.0 (upper-bound y)) (/ 1.0 (lower-bound y))))))]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>One solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.10">Exercise 2.10</a>:</p>
<p><code>(define (spans-zero? x)<br />
  (not (or (positive? (lower-bound x))<br />
           (negative? (upper-bound x)))))</p>
<p>(define (div-interval x y)<br />
  (if (spans-zero? y)<br />
      (error "Divisor spans zero" y)<br />
      (mul-interval x<br />
                    (make-interval (/ 1.0 (upper-bound y))<br />
                                   (/ 1.0 (lower-bound y))))))<br />
</code></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">872</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to SICP Exercise 2.9</title>
		<link>https://kendyck.com/2007/07/08/solution-to-sicp-exercise-29/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Sun, 08 Jul 2007 15:31:47 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/07/08/solution-to-sicp-exercise-29/</guid>

					<description><![CDATA[A solution to Exercise 2.9: Some preliminary definitions: (upper-bound (make-interval a b)) = a [1] (lower-bound (make-interval a b)) = b [2] (width i) = (/ (- (upper-bound i) (lower-bound i)) 2) [3] (add i1 i2) = (make-interval (+ (upper-bound i1) (upper-bound i2)) (+ (lower-bound i1) (lower-bound i2))) [4] Rearranging [3]: (* 2 (width i)) &#8230; <a href="https://kendyck.com/2007/07/08/solution-to-sicp-exercise-29/" class="more-link">Continue reading<span class="screen-reader-text"> "Solution to SICP Exercise&#160;2.9"</span></a>]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>A solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.9">Exercise 2.9</a>:</p>
<p>Some preliminary definitions:</p>
<p><code>(upper-bound (make-interval a b)) = a  [1]<br />
(lower-bound (make-interval a b)) = b  [2]</p>
<p>(width i) = (/ (- (upper-bound i) (lower-bound i)) 2)  [3]</p>
<p>(add i1 i2) = (make-interval (+ (upper-bound i1) (upper-bound i2))<br />
                             (+ (lower-bound i1) (lower-bound i2)))  [4]<br />
</code></p>
<p>Rearranging [3]:</p>
<p><code>(* 2 (width i)) = (- (upper-bound i) (lower-bound i))<br />
(+ (* 2 (width i)) (lower-bound i)) = (upper-bound i)  [5]<br />
</code></p>
<p>From [3]:</p>
<p><code>(width (add i1 i2)) = (/ (- (upper-bound (add i1 i2))<br />
                            (lower-bound (add i1 i2)))<br />
                         2)<br />
</code></p>
<p>Simplifying with [1], [2] and [4]:</p>
<p><code>(width (add i1 i2)) = (/ (- (+ (upper-bound i1)<br />
                               (upper-bound i2))<br />
                            (+ (lower-bound i1)<br />
                               (lower-bound i2)))<br />
                         2)<br />
</code></p>
<p>Substituting in [5]:</p>
<p><code>                    = (/ (- (+ (+ (* 2 (width i1)) (lower-bound i1))<br />
                               (+ (* 2 (width i2)) (lower-bound i2)))<br />
                            (+ (lower-bound i1)<br />
                               (lower-bound i2)))<br />
                         2)</p>
<p>                    = (/ (- (+ (* 2 (width i1)) (* 2 (width i2))<br />
                               (lower-bound i1)<br />
                               (lower-bound i2))<br />
                            (+ (lower-bound i1)<br />
                               (lower-bound i2)))<br />
                         2)<br />
</code></p>
<p>All the (lower-bound x)s cancel out, leaving:</p>
<p><code>                    = (/ (+ (* 2 (width i1))<br />
                            (* 2 (width i2)))<br />
                         2)<br />
</code></p>
<p>So do the 2s:</p>
<p><code>(width (add i1 i2)) = (+ (width i1) (width i2))</code></p>
<p>Clearly the width of the sum is a function only of the width of the operands.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">871</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to Exercise SICP 2.8</title>
		<link>https://kendyck.com/2007/07/07/solution-to-exercise-sicp-28/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Sat, 07 Jul 2007 15:42:10 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/07/07/solution-to-exercise-sicp-28/</guid>

					<description><![CDATA[A solution to Exercise 2.8: The maximum the difference could be is difference between the upper bound of the first interval and the lower bound of the second. The minimum difference is the difference between the lower bound of the first and the upper bound of the second. This holds true even if the second &#8230; <a href="https://kendyck.com/2007/07/07/solution-to-exercise-sicp-28/" class="more-link">Continue reading<span class="screen-reader-text"> "Solution to Exercise SICP&#160;2.8"</span></a>]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>A solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.8">Exercise 2.8</a>:</p>
<p>The maximum the difference could be is difference between the upper bound of the first interval and the lower bound of the second. The minimum difference is the difference between the lower bound of the first and the upper bound of the second. This holds true even if the second interval is greater than the first or the intervals overlap.</p>
<p><code>(define (sub-interval x y)<br />
  (make-interval (- (lower-bound x) (upper-bound y))<br />
                 (- (upper-bound x) (lower-bound y))))<br />
</code></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">870</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to SICP Exercise 2.7</title>
		<link>https://kendyck.com/2007/07/07/solution-to-sicp-exercise-27/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Sat, 07 Jul 2007 15:17:30 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/07/07/solution-to-sicp-exercise-27/</guid>

					<description><![CDATA[A solution to Exercise 2.7: (define (upper-bound interval) (cdr interval)) (define (lower-bound interval) (car interval))]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>A solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.7">Exercise 2.7</a>:</p>
<p><code>(define (upper-bound interval) (cdr interval))<br />
(define (lower-bound interval) (car interval))</code></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">869</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to Exercise SICP 2.6</title>
		<link>https://kendyck.com/2007/07/07/solution-to-sicp-26/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Sat, 07 Jul 2007 14:47:28 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/07/07/solution-to-sicp-26/</guid>

					<description><![CDATA[One solution to Exercise 2.6: (define zero (lambda (f) (lambda (x) x))) (define (add-1 n) (lambda (f) (lambda (x) (f ((n f) x))))) ; (add-1 zero) ; (lambda (f) (lambda (x) (f ((zero f) x)))) ; (lambda (f) (lambda (x) (f (((lambda (g) (lambda (y) y)) f) x)))) ; (lambda (f) (lambda (x) (f ((lambda &#8230; <a href="https://kendyck.com/2007/07/07/solution-to-sicp-26/" class="more-link">Continue reading<span class="screen-reader-text"> "Solution to Exercise SICP&#160;2.6"</span></a>]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>One solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.6">Exercise 2.6</a>:</p>
<p><code>(define zero (lambda (f) (lambda (x) x)))</p>
<p>(define (add-1 n)<br />
  (lambda (f) (lambda (x) (f ((n f) x)))))</p>
<p>; (add-1 zero)<br />
; (lambda (f) (lambda (x) (f ((zero f) x))))<br />
; (lambda (f) (lambda (x) (f (((lambda (g) (lambda (y) y)) f) x))))<br />
; (lambda (f) (lambda (x) (f ((lambda (y) y) x))))<br />
; (lambda (f) (lambda (x) (f x)))<br />
(define one<br />
  (lambda (f) (lambda (x) (f x))))</p>
<p>; (add-1 one)<br />
;(lambda (f) (lambda (x) (f ((one f) x))))<br />
;(lambda (f) (lambda (x) (f (((lambda (g) (lambda (y) (g (y)))) f) x))))<br />
;(lambda (f) (lambda (x) (f ((lambda (y) (f (y))) x))))<br />
;(lambda (f) (lambda (x) (f (f (x)))))<br />
(define two<br />
  (lambda (f) (lambda (x) (f (f x)))))</p>
<p>(define (add a b)<br />
  (lambda (f) (lambda (x) ((a f) ((b f) x)))))</p>
<p>; transform Church numerals to integers (for testing)<br />
(define (to-integer n)<br />
  (define (inc x) (+ 1 x))<br />
  ((n inc) 0))<br />
</code></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">868</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to SICP Exercise 2.5</title>
		<link>https://kendyck.com/2007/06/27/solution-to-sicp-exercise-25/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Thu, 28 Jun 2007 00:39:09 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/06/27/solution-to-sicp-exercise-25/</guid>

					<description><![CDATA[Solution to Exercise 2.5: (define (cons x y) (* (expt 2 x) (expt 3 y))) (define (count-powers n d) (define (iter i pow) (if (zero? (remainder i d)) (iter (/ i d) (+ pow 1)) pow)) (iter n 0)) (define (car c) (count-powers c 2)) (define (cdr c) (count-powers c 3))]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>Solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.5">Exercise 2.5</a>:</p>
<p><code>(define (cons x y)<br />
  (* (expt 2 x)<br />
     (expt 3 y)))</p>
<p>(define (count-powers n d)<br />
  (define (iter i pow)<br />
    (if (zero? (remainder i d))<br />
        (iter (/ i d) (+ pow 1))<br />
        pow))<br />
  (iter n 0))</p>
<p>(define (car c)<br />
  (count-powers c 2))</p>
<p>(define (cdr c)<br />
  (count-powers c 3))<br />
</code></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">867</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
		<item>
		<title>Solution to SICP Exercise 2.4</title>
		<link>https://kendyck.com/2007/06/23/solution-to-sicp-exercise-24/</link>
		
		<dc:creator><![CDATA[kjdyck]]></dc:creator>
		<pubDate>Sat, 23 Jun 2007 12:49:36 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SICP]]></category>
		<guid isPermaLink="false">http://www.kendyck.com/archives/2007/06/23/solution-to-sicp-exercise-24/</guid>

					<description><![CDATA[Solution to Exercise 2.4: Substituting through&#8230; (car (cons x y)) (car (lambda (m) (m x y))) ((lambda (m) (m x y)) (lambda (p q) p)) ((lambda(p q) p) x y) x The definition for cdr: (define (cdr z) (z (lambda (p q) q)))]]></description>
										<content:encoded><![CDATA[<p><a href="http://mitpress.mit.edu/sicp"><img src="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg?w=840" alt="Structure and Interpretation of Computer Programs" /></a></p>
<p>Solution to <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.4">Exercise 2.4</a>:</p>
<p>Substituting through&#8230;</p>
<p><code><br />
(car (cons x y))<br />
(car (lambda (m) (m x y)))<br />
((lambda (m) (m x y)) (lambda (p q) p))<br />
((lambda(p q) p) x y)<br />
x<br />
</code></p>
<p>The definition for <code>cdr</code>:</p>
<p><code>(define (cdr z)<br />
  (z (lambda (p q) q)))<br />
</code></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">866</post-id>
		<media:content url="https://1.gravatar.com/avatar/78fa4b221ff4b38704959d7a9da8de98d4b2975d5be2a29e0aae3c023502c944?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kjdyck</media:title>
		</media:content>

		<media:content url="https://kendyck.com/wp-content/uploads/2016/05/0262011530.jpg" medium="image">
			<media:title type="html">Structure and Interpretation of Computer Programs</media:title>
		</media:content>
	</item>
	</channel>
</rss>
