# egyptian fractions...

8 messages
Open this post in threaded view
|

## egyptian fractions...

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

## Re: (egyptian fractions...) the turtle part: chaos.py

 Am 01.06.2011 22:52, schrieb kirby urner: > > Hey Jeff, your question about controlling the turtle's screen > might have been just the ticket in my attempts to control > chaos, namely G. Lingl's chaos.py, which demonstrates > sensitivity to initial conditions is a plus if you want your > algebra to stay on the same page as itself, per equalities > that won't be equal in the real world.  I'm hoping to throw > that into site-packages on the back end at OST, along with > all those baseball stats in SQL.  It's all done with turtles > (Gregor's thing) and is brilliant, here's a link: > > http://www.4dsolutions.net/ocn/python/OST/chaos.py> > Hi Kirby, it's fine that you "host" a slightly amended version of chaos.py on your website. The original file is part of the demo that ships with Python and the turtledemo has been moved into  the Lib-directory of the standard distribution. Some of these demo-scripts suffer from (more or less minor :-) ) quirks or deficiencies and could be amended in this or that way. I think that such amendments should go into Python 3.3. So if you or anybody else have any ideas, complaints or - as shown here - propositions or results, please let's discuss them, so the turtledemo can obtain not only a demo- but also an enhaced educational value. Best regards Gregor _______________________________________________ Edu-sig mailing list [hidden email] http://mail.python.org/mailman/listinfo/edu-sig
Open this post in threaded view
|

## Re: (egyptian fractions...) the turtle part: chaos.py

 On Wed, Jun 1, 2011 at 17:52, Gregor Lingl <[hidden email]> wrote: > > > Am 01.06.2011 22:52, schrieb kirby urner: >> >> Hey Jeff, your question about controlling the turtle's screen >> might have been just the ticket in my attempts to control >> chaos, namely G. Lingl's chaos.py, which demonstrates >> sensitivity to initial conditions is a plus if you want your >> algebra to stay on the same page as itself, per equalities >> that won't be equal in the real world.  I'm hoping to throw >> that into site-packages on the back end at OST, along with >> all those baseball stats in SQL.  It's all done with turtles >> (Gregor's thing) and is brilliant, here's a link: Baseball stats and turtles? That's something I have been wishing for. I think that the best way to interest children in probability and statistics is sports, including published data and the book Money Ball. Also Nate Silver of the New York Times Five Thirty Eight blog, one of the best analysts of political races (though not of policy), started out in poker and sports. I would like to see your work, and discuss with you and various other people creating an OER with it in the Sugar Labs Replacing Textbooks project. >> http://www.4dsolutions.net/ocn/python/OST/chaos.py>> >> > Hi Kirby, > > it's fine that you "host" a slightly amended version of chaos.py > on your website. > > The original file is part of the demo that ships with Python and > the turtledemo has been moved into  the Lib-directory of the > standard distribution. > > Some of these demo-scripts suffer from (more or less minor :-) ) > quirks or deficiencies and could be amended in this or that way. > > I think that such amendments should go into Python 3.3. So if > you or anybody else have any ideas, complaints or - as shown here - > propositions or results, please let's discuss them, so the turtledemo > can obtain not only a demo- but also an enhaced educational value. > > Best regards > > Gregor > > > _______________________________________________ > Edu-sig mailing list > [hidden email] > http://mail.python.org/mailman/listinfo/edu-sig> -- Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://wiki.sugarlabs.org/go/Replacing_Textbooks_______________________________________________ Edu-sig mailing list [hidden email] http://mail.python.org/mailman/listinfo/edu-sig
Open this post in threaded view
|

## Re: (egyptian fractions...) the turtle part: chaos.py

 In reply to this post by Gregor Lingl-2 On Wed, Jun 1, 2011 at 2:52 PM, Gregor Lingl wrote: Hi Kirby, it's fine that you "host" a slightly amended version of chaos.py on your website. Thanks Gregor.  I've also got John Zelle's graphics.py in the docket.Having any backend code is a somewhat new idea.  I'm tryingto keep a toe hold for Tk, as Eclipse is regarded as "heavy" and if we didn't need widget programming, it'd probably be gone.I think Tk widget programming is valuable exercise with manytransferable skills, for times when you're using other widget  libraries.  Gives important insights into IDLE as well, whichfor better or worse is still what many use out of the box.We had threads here earlier about dropping IDLE from the  standard distro and swapping in something for leading edge.  No candidates came forward though, vindication of Tk in a lotof ways (as a cross-platform solution).  The original file is part of the demo that ships with Python and the turtledemo has been moved into  the Lib-directory of the standard distribution. I've done very few experiments with turtles on the OST server.None of the current Python track courses require it.  Tk, however,is used.  In principle, the turtle stuff, including chaos, should run. My problem is when I run chaos, I'm left with an open windowin the background that I can't seem to close.  This is launchingfrom inside Eclipse, which is usually pretty good with Tk  applications (a major focus in the 2nd course, mixed in withSQL).  Some of these demo-scripts suffer from (more or less minor :-) ) quirks or deficiencies and could be amended in this or that way. I think that such amendments should go into Python 3.3. So if you or anybody else have any ideas, complaints or - as shown here - propositions or results, please let's discuss them, so the turtledemo can obtain not only a demo- but also an enhaced educational value. I have no complaints.  Just wanting to keep Tk on life support, as anaspect of a curriculum I'm helping shape.If we use graphics.py, it'll probably to do some black and orange  brick patterns like in New Kind of Science (Wolfram).  I'm alreadydoing all 256 rules in "ascii art".  Quoting from a console:import sys; print('%s %s' % (sys.executable or sys.platform, sys.version)) C:\Python\python.exe 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)]import ostfrom ost.nks import *Traceback (most recent call last):  File "", line 1, in   File "\\beam\software\Python4\site-packages\ost\nks.py", line 6, in     from lifegame import SensorImportError: No module named lifegameimport ost.lifegame Traceback (most recent call last):  File "", line 1, in   File "\\beam\software\Python4\site-packages\ost\lifegame.py", line 8, in     from farmworld import Farm, Tractor, wordplowImportError: No module named farmworldimport ost.farmworldimport ost.lifegameTraceback (most recent call last):  File "", line 1, in   File "\\beam\software\Python4\site-packages\ost\lifegame.py", line 8, in     from farmworld import Farm, Tractor, wordplowImportError: No module named farmworld Getting nowhere here.  This is a student server and may not have my latest commits to CVS.  Sorry...Kirby  Best regards Gregor _______________________________________________ Edu-sig mailing list [hidden email] http://mail.python.org/mailman/listinfo/edu-sig
Open this post in threaded view
|

## Re: (egyptian fractions...) the turtle part: chaos.py

 In reply to this post by Mokurai On Wed, Jun 1, 2011 at 2:59 PM, Edward Cherlin wrote: Baseball stats and turtles? That's something I have been wishing for. I think that the best way to interest children in probability and statistics is sports, including published data and the book Money Ball. Also Nate Silver of the New York Times Five Thirty Eight blog, one of the best analysts of political races (though not of policy), started out in poker and sports.Yes, I remember your interest.Several of our courses touch on SQL here and there, and when it comesto having some canned, pre-existing tables on the back end, I can  think of fewer richer data mines that the aggregating pool of baseball stats.  I've floated this by other staff and know I have anally in one of the editors.  Question is:  are baseball stats available for MySQL in some open source format, or locked up under lock and key by proprietary dot com pay-per-view services?In a Norman Rockwell future where America gives lip service to  appreciating education, there'd be no problem freely accessing allthese numbers, copying them to the home hard drive.  Maybe this already exists.  I'm in the beginning stages.   I would like to see your work, and discuss with you and various other people creating an OER with it in the Sugar Labs Replacing Textbooks project. I'm trying to condense a lot of concepts into a dense compactedset of modules that aren't too daunting to read, and that don't hide a lot of functionality.  The metaphor of a Turtle has been replacedwith a Tractor in a field (ascii 2d matrix / array).  This isn't aboutdisplacing turtle graphics, it's about creating an analogy that's  even simpler (more primitive).Kirby _______________________________________________ Edu-sig mailing list [hidden email] http://mail.python.org/mailman/listinfo/edu-sig
Open this post in threaded view
|

## Re: (egyptian fractions...) the turtle part: chaos.py

 On Wed, Jun 1, 2011 at 18:56, Kirby Urner <[hidden email]> wrote: > On Wed, Jun 1, 2011 at 2:59 PM, Edward Cherlin <[hidden email]> wrote: >> >> Baseball stats and turtles? That's something I have been wishing for. >> I think that the best way to interest children in probability and >> statistics is sports, including published data and the book Money >> Ball. Also Nate Silver of the New York Times Five Thirty Eight blog, >> one of the best analysts of political races (though not of policy), >> started out in poker and sports. > > Yes, I remember your interest. > Several of our courses touch on SQL here and there, and when it comes > to having some canned, pre-existing tables on the back end, I can > think of fewer richer data mines that the aggregating pool of > baseball stats.  I've floated this by other staff and know I have an > ally in one of the editors.  Question is:  are baseball stats available > for MySQL in some open source format, or locked up under lock > and key by proprietary dot com pay-per-view services? Major League Baseball asserts copyright ownership over everything to do with the American and National Leagues that has not passed into the public domain. For books that means almost anything since 1922. I have no idea who owns rights to the Negro League data and to the data from other countries. I don't know the rules for databases in any detail, although I have heard of court cases declaring that facts cannot be copyrighted, only their specific expression, and that not always. You can buy the complete set of data for US baseball, going back about 150 years, on a CD-ROM. http://www.allprosoftware.com/sb/has commercial products for seven sports, at \$70 or so. We would also need soccer and cricket, at least, which this US company does not offer, and no doubt other sports and games. The Elo international chess rating system is a major work. It has spun off systems for many other tournament games. I have no idea who owns what internationally, given the vast interlocking structure of international governing bodies, leagues, and tournaments. > In a Norman Rockwell future where America gives lip service to > appreciating education, there'd be no problem freely accessing all > these numbers, copying them to the home hard drive.  Maybe > this already exists.  I'm in the beginning stages. Some of it is unquestionably available. >> I would like to see your work, and discuss with you and various other >> people creating an OER with it in the Sugar Labs Replacing Textbooks >> project. >> > > I'm trying to condense a lot of concepts into a dense compacted > set of modules that aren't too daunting to read, and that don't hide > a lot of functionality.  The metaphor of a Turtle has been replaced > with a Tractor in a field (ascii 2d matrix / array). Have you considered Unicode? > This isn't about > displacing turtle graphics, it's about creating an analogy that's > even simpler (more primitive). It should still work for teaching many CS topics. > Kirby Have you ever looked at Befunge, a 2D programming language with a mobile instruction pointer and instructions for changing its direction? It has been described as "a cross between FORTH and Lemmings." ^_^ -- Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://wiki.sugarlabs.org/go/Replacing_Textbooks_______________________________________________ Edu-sig mailing list [hidden email] http://mail.python.org/mailman/listinfo/edu-sig