<?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, 23 Jan 2012 21:54:00 -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-6535</link>
		<dc:creator>administrator</dc:creator>
		<pubDate>Mon, 04 Apr 2011 18:32:35 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-6535</guid>
		<description>John, thank you for discovering and fixing this.  I guess we can take three approaches; 

(1) use #_from in the quicksort procedure 
(2) pass #from as a parameter to the save_pivot procedure
(3) make quicksort a non-local procedure (I made it local so I could assign variable names freely)

I should change the code, but I need to think about these alternatives.</description>
		<content:encoded><![CDATA[<p>John, thank you for discovering and fixing this.  I guess we can take three approaches; </p>
<p>(1) use #_from in the quicksort procedure<br />
(2) pass #from as a parameter to the save_pivot procedure<br />
(3) make quicksort a non-local procedure (I made it local so I could assign variable names freely)</p>
<p>I should change the code, but I need to think about these alternatives.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://peoplesoftsqr.com/index.php/2009/02/quicksort-for-sqr/comment-page-1/#comment-6525</link>
		<dc:creator>John</dc:creator>
		<pubDate>Wed, 30 Mar 2011 21:37:25 +0000</pubDate>
		<guid isPermaLink="false">http://peoplesoftsqr.com/?p=170#comment-6525</guid>
		<description>There is a problem with the &quot;#from&quot; variable.  In the quicksort procedure, this is a local variable.  When the save_pivot procedure tries to reference it, it&#039;s not available.  I change this to the global variable &quot;#_from&quot; in the quicksort procedure and it seems to be working now.</description>
		<content:encoded><![CDATA[<p>There is a problem with the &#8220;#from&#8221; variable.  In the quicksort procedure, this is a local variable.  When the save_pivot procedure tries to reference it, it&#8217;s not available.  I change this to the global variable &#8220;#_from&#8221; in the quicksort procedure and it seems to be working now.</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>

