<br><div>Hey Jeff, your question about controlling the turtle&#39;s screen </div><div>might have been just the ticket in my attempts to control</div><div>chaos, namely G. Lingl&#39;s chaos.py, which demonstrates </div><div>
sensitivity to initial conditions is a plus if you want your </div><div>algebra to stay on the same page as itself, per equalities</div><div>that won&#39;t be equal in the real world.  I&#39;m hoping to throw </div><div>that into site-packages on the back end at OST, along with</div>
<div>all those baseball stats in SQL.  It&#39;s all done with turtles</div><div>(Gregor&#39;s thing) and is brilliant, here&#39;s a link:</div><div><br></div><div><a href="http://www.4dsolutions.net/ocn/python/OST/chaos.py">http://www.4dsolutions.net/ocn/python/OST/chaos.py</a></div>
<div><br></div><div>What I&#39;ve been up to lately, besides teaching Python 24/7,</div><div>is debating with the Egyptologists whether computer science</div><div>really has an algorithm for &quot;Egyptian Fractions&quot;.  Milo is </div>
<div>arguing it doesn&#39;t and the consensus seems to be with </div><div>him for now.  Fibonacci published what&#39;s today often called</div><div>&quot;the greedy algorithm&quot; (though that&#39;s more the genre than</div>
<div>the specimen) and I&#39;m including that in Python below.</div><div><br></div><div>At first I though my job would be to subclass the Fraction</div><div>class in fractions, delegating the nuts and bolts to an </div><div>
internal Fraction but adding this .egyptian( ) method</div><div>(really pseudo).  With that in mind, I storyboarded this</div><div>science fiction session (not yet real) which is another </div><div>way of saying I applied the &quot;agile&quot; principle of &quot;test </div>
<div>driven development&quot;:</div><div><br></div><div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><div><font face="&#39;courier new&#39;, monospace">&gt;&gt;&gt; from unitfractions import Fraction</font></div>
<div><font face="&#39;courier new&#39;, monospace">&gt;&gt;&gt; p = Fraction(5,121)</font></div><div><font face="&#39;courier new&#39;, monospace">&gt;&gt;&gt; type(p)</font></div><div><font face="&#39;courier new&#39;, monospace">&lt;class &#39;unitfractions.Fraction&#39;&gt;</font></div>
<div><font face="&#39;courier new&#39;, monospace">&gt;&gt;&gt; p</font></div><div><font face="&#39;courier new&#39;, monospace">Fraction(5, 121)</font></div><div><font face="&#39;courier new&#39;, monospace">&gt;&gt;&gt; r = p.egyptian( )  # pseudo-egyptian results of Fibonacci-published algorithm</font></div>
<div><font face="&#39;courier new&#39;, monospace">&gt;&gt;&gt; r </font></div><div><font face="&#39;courier new&#39;, monospace">(Fraction(1,25), Fraction(1,757), Fraction(1,763309), Fraction(1,873960180913), Fraction(1,1527612795642093418846225))</font></div>
<div><font face="&#39;courier new&#39;, monospace">&gt;&gt;&gt; sum(r)</font></div><div><font face="&#39;courier new&#39;, monospace">Fraction(5, 121)</font></div></span></div><div><br></div><div>I later decided there was no point trying to maintain the</div>
<div>appearance of a whole new class, and that existing</div><div>Fraction objects should just be fed to this greedy algorithm </div><div>directly, giving a tuple of Fraction outputs. </div><div><br></div><div>Not much code involved.  Keep it Simple (another </div>
<div>&quot;agile&quot; precept).</div><div><br></div><div>From the original thread:</div><div><br></div><div>&quot;&quot;&quot;</div><div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
On second thought, I think subclassing a fractions.Fraction is overkill.  As soon</div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">as said subclass participates in numeric relations with its fellow Fractions</div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">(of the ordinary kind), it&#39;s going to spawn ordinary Fractions (ancestor class).  </div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
<br></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">Maintaining an entirely new type just for this one feature is not worth the effort, </div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
given likely arithmetic relations with peers.</div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
Also, I&#39;m not a huge fan of recursion where iteration is just as straightforward.</div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">In the case of Fibonacci&#39;s greedy algorithm, there&#39;s like nothing to it:</div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><div><font face="&#39;courier new&#39;, monospace" size="4">&quot;&quot;&quot;</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">OST Skunkworks:</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">Pseudo-Egyptian Fractions</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">See:</font></div>
<div class="im" style="color: rgb(80, 0, 80); "><div><font face="&#39;courier new&#39;, monospace" size="4"><a href="http://scienceblogs.com/goodmath/2006/11/egyptian_fractions.php" target="_blank" style="color: rgb(0, 0, 204); ">http://scienceblogs.com/goodmath/2006/11/egyptian_fractions.php</a></font></div>
</div><div><font face="&#39;courier new&#39;, monospace" size="4"><a href="http://groups.google.com/group/mathfuture/browse_thread/thread/97511940cccd5016?hl=en" target="_blank" style="color: rgb(0, 0, 204); ">http://groups.google.com/group/mathfuture/browse_thread/thread/97511940cccd5016?hl=en</a></font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">&quot;&quot;&quot;</font></div><div><font face="&#39;courier new&#39;, monospace" size="4"><br></font></div><div><font face="&#39;courier new&#39;, monospace" size="4">from fractions import Fraction</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">from math import ceil</font></div><div><font face="&#39;courier new&#39;, monospace" size="4"><br></font></div><div><font face="&#39;courier new&#39;, monospace" size="4">def greedy(q):</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">    &quot;&quot;&quot;return unit fraction expansion of fractions.Fraction q,</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    using Fibonacci&#39;s &#39;greedy algorithm&#39; -- non-recursive&quot;&quot;&quot;</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4"><br></font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    results = []    </font></div><div><font face="&#39;courier new&#39;, monospace" size="4"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    while q &gt; 0:</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">        if q.numerator == 1:</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">            results.append(q)</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">            break</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">        x = Fraction(1,ceil(q.denominator / q.numerator))</font></div><div>
<font face="&#39;courier new&#39;, monospace" size="4">        q = q - x</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">        results.append(x)                </font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    return tuple(results)</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4"><br></font></div><div><font face="&#39;courier new&#39;, monospace" size="4">def _test( ):</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    &quot;&quot;&quot;</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">    &gt;&gt;&gt; greedy(Fraction(5,121))</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    (Fraction(1, 25), Fraction(1, 757), Fraction(1, 763309), Fraction(1, 873960180913), Fraction(1, 1527612795642093418846225))</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">    &gt;&gt;&gt; greedy(Fraction(4,5))</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    (Fraction(1, 2), Fraction(1, 4), Fraction(1, 20))</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">    &gt;&gt;&gt; greedy(Fraction(9,31))</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    (Fraction(1, 4), Fraction(1, 25), Fraction(1, 3100))</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">    &gt;&gt;&gt; greedy(Fraction(21,50))</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    (Fraction(1, 3), Fraction(1, 12), Fraction(1, 300))</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">    &gt;&gt;&gt; greedy(Fraction(1023, 1024))</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    (Fraction(1, 2), Fraction(1, 3), Fraction(1, 7), Fraction(1, 44), Fraction(1, 9462), Fraction(1, 373029888))</font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">    &quot;&quot;&quot;</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    print(&quot;testing complete&quot;)</font></div><div><font face="&#39;courier new&#39;, monospace" size="4"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">if __name__ == &quot;__main__&quot;:</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    import doctest</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    doctest.testmod()    </font></div>
<div><font face="&#39;courier new&#39;, monospace" size="4">    _test()</font></div><div><font face="&#39;courier new&#39;, monospace" size="4">    </font></div></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
<font face="&#39;courier new&#39;, monospace" size="4"><span style="font-family: arial; font-size: small; "><div>Note that I&#39;m calling these &quot;pseudo Egyptian&quot; -- not claiming there&#39;s any simple</div><div>
algorithmic solution that&#39;ll work best in all cases.  Computer scientists and</div><div>Milo appear to be on the same side on this one.</div><div>&quot;&quot;&quot;</div></span></font></div></div><div><br></div><div>The threads on all this may be dredged up from an obscure Google </div>
<div>group named mathfuture, one of the Droujkova facilities, and as </div><div>usual productive.</div><div><br></div><div>Kirby</div><div><br></div>