<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Quicksort For SQR</title>
	<atom:link href="http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/feed/" rel="self" type="application/rss+xml" />
	<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/</link>
	<description>When Peoplebooks Is Not Enough</description>
	<lastBuildDate>Mon, 16 Aug 2010 16:52:22 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: administrator</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-105</link>
		<dc:creator>administrator</dc:creator>
		<pubDate>Thu, 26 Feb 2009 22:30:32 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-105</guid>
		<description>This is better than what I had in mind; you&#039;ve basically written a specialized, three element insertion sort.  The advantage of this is that you could extend it to four elements more easily than extending a mathematical solution.  The next step would be to try a three element bubble sort.</description>
		<content:encoded><![CDATA[<p>This is better than what I had in mind; you&#8217;ve basically written a specialized, three element insertion sort.  The advantage of this is that you could extend it to four elements more easily than extending a mathematical solution.  The next step would be to try a three element bubble sort.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-103</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Thu, 26 Feb 2009 20:04:12 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-103</guid>
		<description>Well, the thing about using the mathematical method is that I&#039;m always slightly nervous that some math-implementation issue ( e.g. rounding errors ) might show up at some point in the life of the application.  Given a choice, I&#039;d lean toward straight MOVEs rather than relying on floating-point arithmetic, even though I know that most applications where SQR is used don&#039;t involve numbers that push any implementation limits.

So, I&#039;d want to at least implement my &quot;min_max&quot; routine above with a simple IF statement (no nesting would be required for a two-variable min/max) instead of using calculations.  (That would still leave the LET expression that calculats #mid, but I trust addition more than division. :) )

But really I&#039;d probably want to replace both min_max and min_mid_max with the following:


&lt;code&gt;begin-procedure min_mid_max_if(#x, #y, #z, :#min, :#mid, :#max)&lt;/code&gt;

&lt;code&gt;move #x to #min&lt;/code&gt;

&lt;code&gt;if #y &lt; #min
&#160;&#160;move #min to #mid
&#160;&#160;move #y to #min
else 
&#160;&#160;move #y to #mid
end-if&lt;/code&gt;

&lt;code&gt;if #z &lt; #min
&#160;&#160;move #mid to #max
&#160;&#160;move #min to #mid
&#160;&#160;move #z to #min
else 
&#160;&#160;if #z &lt; #mid
&#160;&#160;&#160;&#160;move #mid to #max
&#160;&#160;&#160;&#160;move #z to #mid
&#160;&#160;else
&#160;&#160;&#160;&#160;move #z to #max
&#160;&#160;end-if
end-if&lt;/code&gt;

&lt;code&gt;end-procedure ! min_mid_max_if&lt;/code&gt;


Although this routine involves more lines of code than the min_max/min_mid_max combo, I think it is somewhat easier to understand what each line is trying to accomplish (and it involves no arithmetic calculations at all)....</description>
		<content:encoded><![CDATA[<p>Well, the thing about using the mathematical method is that I&#8217;m always slightly nervous that some math-implementation issue ( e.g. rounding errors ) might show up at some point in the life of the application.  Given a choice, I&#8217;d lean toward straight MOVEs rather than relying on floating-point arithmetic, even though I know that most applications where SQR is used don&#8217;t involve numbers that push any implementation limits.</p>
<p>So, I&#8217;d want to at least implement my &#8220;min_max&#8221; routine above with a simple IF statement (no nesting would be required for a two-variable min/max) instead of using calculations.  (That would still leave the LET expression that calculats #mid, but I trust addition more than division. <img src='http://peoplesoftsqr.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<p>But really I&#8217;d probably want to replace both min_max and min_mid_max with the following:</p>
<p><code>begin-procedure min_mid_max_if(#x, #y, #z, :#min, :#mid, :#max)</code></p>
<p><code>move #x to #min</code></p>
<p><code>if #y &lt; #min<br />
&nbsp;&nbsp;move #min to #mid<br />
&nbsp;&nbsp;move #y to #min<br />
else<br />
&nbsp;&nbsp;move #y to #mid<br />
end-if</code></p>
<p><code>if #z &lt; #min<br />
&nbsp;&nbsp;move #mid to #max<br />
&nbsp;&nbsp;move #min to #mid<br />
&nbsp;&nbsp;move #z to #min<br />
else<br />
&nbsp;&nbsp;if #z &lt; #mid<br />
&nbsp;&nbsp;&nbsp;&nbsp;move #mid to #max<br />
&nbsp;&nbsp;&nbsp;&nbsp;move #z to #mid<br />
&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;move #z to #max<br />
&nbsp;&nbsp;end-if<br />
end-if</code></p>
<p><code>end-procedure ! min_mid_max_if</code></p>
<p>Although this routine involves more lines of code than the min_max/min_mid_max combo, I think it is somewhat easier to understand what each line is trying to accomplish (and it involves no arithmetic calculations at all)&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: administrator</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-100</link>
		<dc:creator>administrator</dc:creator>
		<pubDate>Thu, 26 Feb 2009 17:06:17 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-100</guid>
		<description>I think you&#039;ve found the simplest approach, maybe even simpler than using IF statements.  I&#039;ve tried to sketch out the code with IF statements in my head and it was surprisingly complicated.</description>
		<content:encoded><![CDATA[<p>I think you&#8217;ve found the simplest approach, maybe even simpler than using IF statements.  I&#8217;ve tried to sketch out the code with IF statements in my head and it was surprisingly complicated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-98</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Thu, 26 Feb 2009 05:26:22 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-98</guid>
		<description>Okay, I was thinking you might be trying to go down the &quot;algebra&quot; road....

For the two-variable case, I remembered from years ago the trick that relies on the fact that the average of two numbers is half-way between them, so if you start at the average and then move one-half of the difference between the two numbers you end back at one of the original two numbers -- and by controling which direction you move, you will arrive at either the smaller or the larger of the two.

So, simplifying the formula and converting it into SQR code produces:


&lt;code&gt;begin-procedure min_max(#x, #y, :#min, :#max) 
let #min= ( #x + #y - abs(#x - #y) )/2
let #max= ( #x + #y + abs(#x - #y) )/2
end-procedure&lt;/code&gt;


For the three-variable case, I wasn&#039;t able to convince myself that any code would be &quot;simpler&quot; than breaking down the problem into pairs and invoking the two-variable procedure on each pair:


&lt;code&gt;begin-procedure min_mid_max(#x, #y, #z, :#min, :#mid, :#max)
do min_max(#x, #y, #lower, #higher)
do min_max(#lower, #z, #min, #dummy1)
do min_max(#higher, #z, #dummy2, #max)
let #mid= #x + #y + #z - #min - #max
end-procedure&lt;/code&gt;


(We know that at least one of #dummy1 or #dummy2 is going to be #mid, but we don&#039;t know which one, so as long as we are avoiding IF commands we just use addition/subtraction to calculate #mid.)


Did you find anything simpler than that?   (Well, other than just using IF, which would clearly be much simpler :) )</description>
		<content:encoded><![CDATA[<p>Okay, I was thinking you might be trying to go down the &#8220;algebra&#8221; road&#8230;.</p>
<p>For the two-variable case, I remembered from years ago the trick that relies on the fact that the average of two numbers is half-way between them, so if you start at the average and then move one-half of the difference between the two numbers you end back at one of the original two numbers &#8212; and by controling which direction you move, you will arrive at either the smaller or the larger of the two.</p>
<p>So, simplifying the formula and converting it into SQR code produces:</p>
<p><code>begin-procedure min_max(#x, #y, :#min, :#max)<br />
let #min= ( #x + #y - abs(#x - #y) )/2<br />
let #max= ( #x + #y + abs(#x - #y) )/2<br />
end-procedure</code></p>
<p>For the three-variable case, I wasn&#8217;t able to convince myself that any code would be &#8220;simpler&#8221; than breaking down the problem into pairs and invoking the two-variable procedure on each pair:</p>
<p><code>begin-procedure min_mid_max(#x, #y, #z, :#min, :#mid, :#max)<br />
do min_max(#x, #y, #lower, #higher)<br />
do min_max(#lower, #z, #min, #dummy1)<br />
do min_max(#higher, #z, #dummy2, #max)<br />
let #mid= #x + #y + #z - #min - #max<br />
end-procedure</code></p>
<p>(We know that at least one of #dummy1 or #dummy2 is going to be #mid, but we don&#8217;t know which one, so as long as we are avoiding IF commands we just use addition/subtraction to calculate #mid.)</p>
<p>Did you find anything simpler than that?   (Well, other than just using IF, which would clearly be much simpler <img src='http://peoplesoftsqr.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: administrator</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-93</link>
		<dc:creator>administrator</dc:creator>
		<pubDate>Tue, 24 Feb 2009 22:15:25 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-93</guid>
		<description>I wanted to avoid IF because the solution with IF isn&#039;t much of a brain teaser.  COND() and RANGE() are good solutions, although they merely move the IF operation into the function.  There are ways to get MIN and MAX without comparing the inputs.  Note that the puzzle uses numeric variables, not string variables.</description>
		<content:encoded><![CDATA[<p>I wanted to avoid IF because the solution with IF isn&#8217;t much of a brain teaser.  COND() and RANGE() are good solutions, although they merely move the IF operation into the function.  There are ways to get MIN and MAX without comparing the inputs.  Note that the puzzle uses numeric variables, not string variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-91</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Tue, 24 Feb 2009 21:45:46 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-91</guid>
		<description>Regarding the brain teaser:

Why are we avoiding IF?  Can we use the cond() function?  How about range()?  Or are you trying to stick with &quot;math&quot; functions like sign()?</description>
		<content:encoded><![CDATA[<p>Regarding the brain teaser:</p>
<p>Why are we avoiding IF?  Can we use the cond() function?  How about range()?  Or are you trying to stick with &#8220;math&#8221; functions like sign()?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AdvandyBainia</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-88</link>
		<dc:creator>AdvandyBainia</dc:creator>
		<pubDate>Tue, 24 Feb 2009 06:48:58 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-88</guid>
		<description>Thank you!</description>
		<content:encoded><![CDATA[<p>Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: administrator</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-62</link>
		<dc:creator>administrator</dc:creator>
		<pubDate>Mon, 09 Feb 2009 21:41:15 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-62</guid>
		<description>You&#039;re right on both counts.

First, FORTRAN, the IBM FORmula TRANslating System, had integer variables and floating point variables.  Fortran variable names that started with I through N were integers.

Second, Fortran allowed variables with up to five or six character names (I forget which).  I don&#039;t know whether that was in the first version; my earliest experience was with Fortran II and most of my experience was with Fortran IV.  In Fortran IV, any variable could be declared as an integer.</description>
		<content:encoded><![CDATA[<p>You&#8217;re right on both counts.</p>
<p>First, FORTRAN, the IBM FORmula TRANslating System, had integer variables and floating point variables.  Fortran variable names that started with I through N were integers.</p>
<p>Second, Fortran allowed variables with up to five or six character names (I forget which).  I don&#8217;t know whether that was in the first version; my earliest experience was with Fortran II and most of my experience was with Fortran IV.  In Fortran IV, any variable could be declared as an integer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Josephson</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-61</link>
		<dc:creator>Bob Josephson</dc:creator>
		<pubDate>Mon, 09 Feb 2009 20:41:35 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-61</guid>
		<description>OK: in the mid-1950s (before I was born - just for the record) FORTRAN defined variables as integers if their names started with an I, J, K, L, M, or N. Variables starting with other letters were real numbers.

So &#039;I&#039; was just the first and shortest legal choice for an integer loop counter.

Now, I don&#039;t have encyclopedic knowledge of features introduced in each version of FORTRAN, but at some point it allowed programmers to explicitly declare variables with any name to have any type. Is that what you&#039;re referring to as the solution introduced in FORTRAN II?

(Of course, I was being facetious in the first place about the problem with nested loop variables. Even the original FORTRAN allowed variables with multi-character names. As for the ancient Romans, they used APL, thus causing Servilius Casca to famously complain &quot;it was Greek to me.&quot;)

As for recursion not being necessary: sure, you can, with varying degrees of difficulty, survive without it. But the same is true of the EVALUATE statement, and you were keeping score for that. I detect blatant pro-SQR bias!! :-)</description>
		<content:encoded><![CDATA[<p>OK: in the mid-1950s (before I was born &#8211; just for the record) FORTRAN defined variables as integers if their names started with an I, J, K, L, M, or N. Variables starting with other letters were real numbers.</p>
<p>So &#8216;I&#8217; was just the first and shortest legal choice for an integer loop counter.</p>
<p>Now, I don&#8217;t have encyclopedic knowledge of features introduced in each version of FORTRAN, but at some point it allowed programmers to explicitly declare variables with any name to have any type. Is that what you&#8217;re referring to as the solution introduced in FORTRAN II?</p>
<p>(Of course, I was being facetious in the first place about the problem with nested loop variables. Even the original FORTRAN allowed variables with multi-character names. As for the ancient Romans, they used APL, thus causing Servilius Casca to famously complain &#8220;it was Greek to me.&#8221;)</p>
<p>As for recursion not being necessary: sure, you can, with varying degrees of difficulty, survive without it. But the same is true of the EVALUATE statement, and you were keeping score for that. I detect blatant pro-SQR bias!! <img src='http://peoplesoftsqr.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: administrator</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-60</link>
		<dc:creator>administrator</dc:creator>
		<pubDate>Mon, 09 Feb 2009 19:04:18 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-60</guid>
		<description>You seem to know the answer, so why don&#039;t you explain it for the readers who aren&#039;t as old as you are?  If you do, I&#039;ll tell you how Fortran II (yes, it was identified with roman numerals) supported more than six nested loops - for the sake of the readers who aren&#039;t as old as I am.

I stopped keeping score between SQR and C because I demonstrated that recursion is completely unnecessary.  Next week, I will debunk pointers  (smirk).</description>
		<content:encoded><![CDATA[<p>You seem to know the answer, so why don&#8217;t you explain it for the readers who aren&#8217;t as old as you are?  If you do, I&#8217;ll tell you how Fortran II (yes, it was identified with roman numerals) supported more than six nested loops &#8211; for the sake of the readers who aren&#8217;t as old as I am.</p>
<p>I stopped keeping score between SQR and C because I demonstrated that recursion is completely unnecessary.  Next week, I will debunk pointers  (smirk).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
