From kurner at oreillyschool.com Sun Mar 2 07:47:28 2014 From: kurner at oreillyschool.com (Kirby Urner) Date: Sat, 1 Mar 2014 22:47:28 -0800 Subject: [Edu-sig] Just for Fun: Another Fractal (ASCII output) Message-ID: """ Just for Fun: Simple Fractal (ASCII art) (cc) Kirby Urner, MIT license 4dsolutions.net """ class M: """ Plant an M-Seed and call it, in each cell of the Garden """ depth = 7 def __init__(self, x, y): self.c = complex(x,y) def __call__(self): z = 0+0j for _ in range(M.depth): z = z**2 + self.c return z class Fractal(dict): """ This is the Garden, a complex plane planted with M-Seeds Inherit from dict to store complex numbers in key (x,y) """ def __init__(self, left_x, top_y, right_x, bottom_y): """Top Left, Top, Far Right, Bottom""" super().__init__() self.left_x = left_x y = self.top_y = top_y self.right_x, self.bottom_y = right_x, bottom_y while y >= bottom_y: x = left_x while x < right_x: self[(x,y)] = M(x,y)() # plant seed and call it x += 0.02 y -= 0.05 def __str__(self): """ Reap the harvest """ rows = "" y = self.top_y while y >= self.bottom_y: row="" x = self.left_x while x <= self.right_x: v = abs(self[(x,y)]) # calibrate by magnitude of stored value if v >= 2: row += "." elif 2 > v >= 1.5: row += "^" elif 1.5 > v >= 1.3: row += "+" elif 1.3 > y >= 1.0: row += "@" else: row += "@" x += 0.02 rows += row + "\n" y -= 0.05 return rows if __name__ == "__main__": # run me and open the file in a text editor to see 'fractal' f = Fractal(-2.2, 1.4, 0.8, -1.4) with open("mandelbrot.txt","w") as mandelbrot: print(f, file = mandelbrot) -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurner at oreillyschool.com Sun Mar 2 21:34:34 2014 From: kurner at oreillyschool.com (Kirby Urner) Date: Sun, 2 Mar 2014 12:34:34 -0800 Subject: [Edu-sig] Just for Fun: Another Fractal (ASCII output) In-Reply-To: References: Message-ID: Below is an add-on to the above simple fractal maker allowing for POV-Ray output. Here are screen shots of the output: http://flic.kr/p/kCDaRB (ASCII art) http://flic.kr/p/kCLp2F (POV-Ray) Since the "ASCII canvas" is denser in the X than Y direction, my little jumps in the complex plane were 0.02 and 0.05 respectively. But the POV-Ray canvas looks better if each cell is a square or sphere -- I'll use spheres but of course feel free to tweek / alter this code however -- and jumps of 0.02 in both directions. So the sphere radius is 0.01 (half a jump). The Fractal class will need to be updated accordingly i.e. in __init__: x += 0.02 y -= 0.02 # <--- changed from 0.05 and in __str__ in you like (it won't work unless the address keys are the same -- but __str__ isn't needed for outputting in .pov format). Then, and the end of the file you might do as follows, to preserve raw ASCII output as an option: def _test1(): # run me and open the file in a text editor to see 'fractal' f = Fractal(-2.2, 1.4, 0.8, -1.4) with open("mandelbrot.txt","w") as mandelbrot: print(f, file = mandelbrot) def _test2(): # run me and then render me in POV-Ray to see 'fractal' f = Fractal(-2.2, 1.4, 0.8, -1.4) pov_out.make_file(f) # mandelbrot.pov is the output if __name__ == "__main__": _test2() Below is the pov_out module, to be imported. Kirby """ Just for Fun: Simple Fractal -> POV-Ray file -- for import into simple_fractal.py or import simple_fractal into this module (cc) Kirby Urner, MIT license 4dsolutions.net Example bash command lines to generate the output file and then render it into a PNG file: mackurner:Documents kurner$ python3 simple_fractal.py mackurner:Documents kurner$ povray +Imandelbrot.pov +A[0.1] +W1024 +H768 Example output: http://flic.kr/p/kCLp2F (the PNG file, unedited) """ template = """\ #include "colors.inc" #include "textures.inc" #include "shapes.inc" camera { location<-1,0,-3> // standpoint of the viewer look_at <-1,0,0> // where to look at right x*image_width/image_height // aspect ratio angle 0 // camera angle } light_source{ <1000,1000,-1500> color White} """ sphere_tmpl = """\ sphere{{ <{x},{y},{z}>, {radius} texture{{ pigment{{ color {color} }} }} // end texture }} // end sphere """ def make_pov(F): """ eat Fractal object, output POV-ray spheres for inclusion in a POV-Ray file """ rows = "" y = F.top_y radius = 0.01 while y >= F.bottom_y: row= "" x = F.left_x while x <= F.right_x: v = abs(F[(x,y)]) # calibrate by magnitude of stored value if v >= 2: color = "rgb<1,1,1>" elif 2 > v >= 1.5: color = "rgb<1,0.65,0>" elif 1.5 > v >= 1.3: color = "rgb<0.45,0.45,0>" elif 1.3 > y >= 1.0: color = "rgb<0.25,0.25,0>" else: color = "rgb<0.25,0.25,0>" row += sphere_tmpl.format(x=x, y=y, z=0, radius=radius, color=color) x += 0.02 rows += row y -= 0.02 return rows def make_file(the_fractal): """ eat a Fractal type object, a subclass of dict with complex numbers already stored in each cell, a result of processing M-seed type objects """ # write the file with open("mandelbrot.pov", "w") as povout: povout.write(template) # header body = make_pov(the_fractal) povout.write(body) # main content -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurner at oreillyschool.com Tue Mar 4 21:32:50 2014 From: kurner at oreillyschool.com (Kirby Urner) Date: Tue, 4 Mar 2014 12:32:50 -0800 Subject: [Edu-sig] Just for Fun: Another Fractal (ASCII output) In-Reply-To: References: Message-ID: Just to conclude the the code part (from me), I realized while walking this morning that POV-Ray scene description language is such that the ordering of sphere placement would not matter, so just iterate through the keys. The code before tried to construct the keys by duplicating the raster pattern of the Fractal's __init__ -- quite unnecessarily. def __init__(self, left_x, top_y, right_x, bottom_y, delta_x, delta_y): """Top Left, Top, Far Right, Bottom, x increment, y increment""" As also suggested by F.delta_x below, I also modified Fractal in an obvious way: to accept delta_x and delta_y as arguments, along with: x minimum (left), y maximum (top), x maximum (right), y minimum (bottom). If this were scaffolding in a class setting, a next iteration might involve jiggering the API, to accept (top, left) and (bottom, right) as tuples perhaps. Here's the revised make_pov function: def make_pov(F): """ eat Fractal object, output POV-ray spheres for inclusion in a POV-Ray file """ rows = "" radius = F.delta_x/2 for x,y in F: v = abs(F[(x,y)]) # calibrate by magnitude of stored value if v >= 3: color = "rgb<1,1,1>" elif 3 > v >= 2.5: color = "rgb<1,0.65,0>" elif 2.5 > v >= 1.5: color = "rgb<0.45,0.45,0>" elif 1.5 > y >= 1.0: color = "rgb<0.25,0.25,0>" else: color = "rgb<0.25,0.25,0>" rows += sphere_tmpl.format(x=x, y=y, z=0, radius=radius, color=color) return rows And here's a screen shot of what I get for running the Python below: http://www.flickr.com/photos/kirbyurner/12934900014/lightbox/ def _test2(): # run me and then render me in POV-Ray to see 'fractal' f = Fractal(-2.2, 1.4, 0.8, -1.4, 0.005, 0.005) pov_out.make_file(f) # mandelbrot.pov is the output ...and in bash: povray +Imandelbrot.pov +A[0.1] +W1024 +H768 I've been into Python + Fractals before here on edu-sig. Here's a solution using PIL: http://4dsolutions.net/ocn/fractals.html And in this one I use VPython to play Game of Life (also Chaos Math) on a hexapent: http://4dsolutions.net/ocn/life.html Then there's the Wolfram / NKS stuff ("new kind of science"), very doable in tkinter for example: http://www.frank-buss.de/automaton/rule30.html Lots of people work in this area. I've done nothing with Python and the Mandelbulb. Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurner at oreillyschool.com Wed Mar 5 04:23:29 2014 From: kurner at oreillyschool.com (Kirby Urner) Date: Tue, 4 Mar 2014 19:23:29 -0800 Subject: [Edu-sig] reviewing the context manager construct Message-ID: """ Just for Fun A quick sketch of a Context Manager construct. A context manager is a type instance with an __enter__ and __exit__ protocol, and designed to work with a suite indented under a "with statement" (cc) Kirby Urner, MIT License O'Reilly School of Technology Sebastopol, CA With thanks to: http://www.greatplay.net/uselessia/articles/e2-1000.html """ import decimal class Haunted_Castle: """ Shows the workflow of a context manager """ def __enter__(self): print("Welcome to my world...") return self def __exit__(self, *stuff): print("Sorry to see you leave. Come back again soon.") return True # handled exception def __repr__(self): return "Context manager object at: {}".format(id(self)) print("Before the context scope...") with Haunted_Castle() as ctx: print("This is the suite within the scope of the context") print("Available from inside:", repr(ctx)) raise Exception # raise a fuss print("After context...") # and now that we have introduced the concept, here is one way # to use it in practice: temporarily boost the precision of # Decimal type objects beyond a default of 28 decimal digits # of precision print("Do a big decimal computation...") print("Default precision is:", decimal.getcontext().prec) with decimal.localcontext() as ctx: ctx.prec = 500 print("Precision in suite:", decimal.getcontext().prec) n = decimal.Decimal("1"+"0"*300) # 100000....0 (300 zeros) result = str((1 + 1/n) ** n) # converges to Euler's e print("Default precision is:", decimal.getcontext().prec) # as in math.e but to more digits (1000) euler = """\ 2. 7182818284 5904523536 0287471352 6624977572 4709369995 9574966967 6277240766 3035354759 4571382178 5251664274 2746639193 2003059921 8174135966 2904357290 0334295260 5956307381 3232862794 3490763233 8298807531 9525101901 1573834187 9307021540 8914993488 4167509244 7614606680 8226480016 8477411853 7423454424 3710753907 7744992069 5517027618 3860626133 1384583000 7520449338 2656029760 6737113200 7093287091 2744374704 7230696977 2093101416 9283681902 5515108657 4637721112 5238978442 5056953696 7707854499 6996794686 4454905987 9316368892 3009879312 7736178215 4249992295 7635148220 8269895193 6680331825 2886939849 6465105820 9392398294 8879332036 2509443117 3012381970 6841614039 7019837679 3206832823 7646480429 5311802328 7825098194 5581530175 6717361332 0698112509 9618188159 3041690351 5988885193 4580727386 6738589422 8792284998 9208680582 5749279610 4841984443 6346324496 8487560233 6248270419 7862320900 2160990235 3043699418 4914631409 3431738143 6405462531 5209618369 0888707016 7683964243 7814059271 4563549061 3031072085 1038375051 0115747704 1718986106 8739696552 1267154688 9570350354\ """ #remove spaces and newlines euler = euler.replace(" ", "") euler = euler.replace("\n", "") # the result of the computation matches the published value to how many digits? c=0 while True: if euler[c] != result[c]: print("Same to {} places".format(c)) break c += 1 #show significant digits #print(euler[:c]) #print(result[:c]) -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurner at oreillyschool.com Wed Mar 5 06:17:41 2014 From: kurner at oreillyschool.com (Kirby Urner) Date: Tue, 4 Mar 2014 21:17:41 -0800 Subject: [Edu-sig] A Descriptor (demonstrating the concept) Message-ID: """ Just for Fun A quick sketch of a Descriptor construct. A descriptor is a type instance with a __get __ and __set__ protocol, also __delete__, and designed to satisfy a common need to manage setting and getting with mediating methods. http://docs.python.org/3.4/howto/descriptor.html (cc) Kirby Urner, MIT License O'Reilly School of Technology """ class Guardian: """ Takes a field name and a function for screening out banned values for said field name """ def __init__(self, fn, banned): self.field = fn self.banned = banned def __set__(self, obj, val): # print("Setting {} on {}".format(self.field, obj)) if self.banned(val): raise AttributeError("Can't be {}".format(val)) obj.__dict__[self.field] = val def __get__(self, obj, objtype): objtype.ringding() # calls class method return obj.__dict__[self.field] class Guest: # data descriptors age = Guardian("age", banned = lambda a: a in range(1,21)) # 21 or older fave_color = Guardian("fave_color", banned = lambda c: c in ["Orange", "Black"]) def __init__(self, n, age=0, fc=None): self.name = n # data descriptors always override instance dictionaries. self.age = age self.fave_color = fc @classmethod def ringding(cls): # called by __get__ in data descriptors print("Ring Ding!") def __repr__(self): return "Guest of name {}".format(self.name) t1 = Guest('Helga', 40) t2 = Guest('Vlad', 30) print("Age of t2:", t2.age) try: t1.age = 11 # comes up against banned() except AttributeError: print("No can do: 11") try: t1.fave_color = "Orange" # ditto banned() except AttributeError: print("No can do: Orange") t1.age = 22 t1.fave_color = "Green" # attributes stick to their respective instances if legal print(t1.age) print(t1.fave_color) print(t2.age) -------------- next part -------------- An HTML attachment was scrubbed... URL: From andre.roberge at gmail.com Fri Mar 14 02:41:14 2014 From: andre.roberge at gmail.com (Andre Roberge) Date: Thu, 13 Mar 2014 22:41:14 -0300 Subject: [Edu-sig] Reeborg news Message-ID: The long-time subscribers to this list may remember RUR-PLE ( https://code.google.com/p/rur-ple/), a Karel-the-robot clone using Python that I wrote. The robot's name in my version is Reeborg, hence the title of this post. Since the last version was produced in 2009, RUR-PLE had been downloaded more than 11,000 times. Since people that download it do not need to contact me to do so, it is only through serependity that I find out where it is used. I know that it has been used by elementary school children in Austria, by high school children in New Jersey and by university students in the U.S. and Latin America as a tool to introduce Python. Recently, Samsung contacted me and got my permission to produce a book based on RUR-PLE. They distributed free copies of this book yesterday to something like 1000 Korean students. (I will likely post pictures of the book on my blog when I get a copy.) So what you say?.... I am happy to announce that a test-version of "Reeborg's world" is now available online as a tool to learn Python. It is free to use and does not require registration. The first version of Reeborg's world was produced to teach Javascript; it is the default version available from http://reeborg.ca. It includes some 98 lessons and can be found directly at http://reeborg.ca/learn_js.html I'm working on an "improved" version which can be found at http://reeborg.ca/learn_js_dev.html#welcome Following some comments by early adopters, the UI of this version is improved slightly and more changes are planned, including a graphical world builder, new images for the robot, the option to import from file and save to file programs and worlds, etc. The proof-of-concept Python version can be found at http://reeborg.ca/learn_py_test.html It is based on the "improved" version. I do not plan to do more work on it (including adapting the lessons to teach Python instead of Javascript) until I have nailed down the "improved" Javascript version. If you want to quickly try the Python version to see what it can do, I suggest you select (from the drop down menu showing "Alone" by default) the world "Tokens 1" and run the following program: move() take() move() put() move() I welcome any comments & suggestions about Reeborg's world; please feel free to email me directly. This time, I will probably include a page on the site where I will ask teachers that use it to communicate with me to let me know in what context they use it, and keep track of it on a "wall of fame". -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Fri Mar 14 04:34:13 2014 From: kirby.urner at gmail.com (kirby urner) Date: Thu, 13 Mar 2014 20:34:13 -0700 Subject: [Edu-sig] Reeborg news In-Reply-To: References: Message-ID: This is all great news Andre. Interesting packages that "dissect themselves" in a "what makes me tick" way are doubly valuable, at least doubly. Reeborg's World, which I just visited, looks really friendly / accessible, a great way to learn. I starting move( )-ing immediately. I look forward to going through this literature (perhaps including the JavaScript version, as materials to teach that "very important language" -- VIL? -- are on my radar). I really like having sites / materials like this to re-visit and study as I flit about from here to there (was just in Philadelphia, more bouncing around to come). Thank you for enriching our shared environment. Kirby On Thu, Mar 13, 2014 at 6:41 PM, Andre Roberge wrote: > The long-time subscribers to this list may remember RUR-PLE ( > https://code.google.com/p/rur-ple/), a Karel-the-robot clone using Python > that I wrote. The robot's name in my version is Reeborg, hence the title > of this post. > > Since the last version was produced in 2009, RUR-PLE had been downloaded > more than 11,000 times. Since people that download it do not need to > contact me to do so, it is only through serependity that I find out where > it is used. I know that it has been used by elementary school children in > Austria, by high school children in New Jersey and by university students > in the U.S. and Latin America as a tool to introduce Python. > > << SNIP >> > > > I welcome any comments & suggestions about Reeborg's world; please feel > free to email me directly. > > This time, I will probably include a page on the site where I will ask > teachers that use it to communicate with me to let me know in what context > they use it, and keep track of it on a "wall of fame". > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Sun Mar 16 03:16:24 2014 From: kirby.urner at gmail.com (kirby urner) Date: Sat, 15 Mar 2014 19:16:24 -0700 Subject: [Edu-sig] round trip with unicode (the Latin-1 neighborhood) Message-ID: Round Trip in UTF-8: Two Byte Encodings Explanation: Latin-1 includes all of 127 7-bit ASCII and begins the 2-byte encodings in UTF-8. Below, Latin-1 character at code point 200 is represented as bytes then broken down into bits. When utf-8 needs two bytes (it might use up to six), the leading byte begins 110 to signify that, and the followup byte begins 10. So the significant payload bits are just 11001000 which Python shows is 200, where we started. http://youtu.be/vLBtrd9Ar28 (see chart @ 10:30) Leading byte begins 0xxxxxxx - this is the only byte 110xxxxx - another byte after this 1110xxxx - two more bytes 11110xxx - three more bytes 111110xx - four more bytes 1111110x - a total of six bytes x means 'room for payload' Console session: Python 3.2.3 (v3.2.3:3d0686d90f55, Apr 10 2012, 11:09:56) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin sys.path.extend(['/Users/kurner/Documents']) >>> import sys >>> sys.getdefaultencoding() 'utf-8' >>> chr(200) '?' >>> bytes(chr(200), encoding='utf-8') b'\xc3\x88' >>> bin(0xc3) # left byte in bits '0b11000011' >>> bin(0x88) # right byte in bits '0b10001000' >>> 0b11001000 # the encoded number 200 -------------- next part -------------- An HTML attachment was scrubbed... URL: From andre.roberge at gmail.com Fri Mar 21 13:58:02 2014 From: andre.roberge at gmail.com (Andre Roberge) Date: Fri, 21 Mar 2014 09:58:02 -0300 Subject: [Edu-sig] Reeborg news In-Reply-To: References: Message-ID: Testers wanted! There is now a major update of the Python version of Reeborg's world, still available at the same link I quoted before. A few major things missing: actual Python lessons, the help window and a graphical world builder. So, you have to refer to the default javascript version to see what commands are actually available. Reeborg's world is intended as a replacement for both rur-ple (which I wrote) and possibly rurple NG (written by Paul Crowley as he aimed to remove some perceived warts in the original), with significant additional capabilities. If you are using rurple or rurple ng in a teaching environment (or even possibly Guido van Robot), and would like to influence Reeborg's world development so that it is even better than the predecessors, please feel free to contact me directly. Andr? P.S. to use the "library" in the new Python version, its actual name when called from a program is simply "lib"; it is not loaded automatically. You know how to do the rest. (However, do not include comments on that line.) On Thu, Mar 13, 2014 at 10:41 PM, Andre Roberge wrote: > The long-time subscribers to this list may remember RUR-PLE ( > https://code.google.com/p/rur-ple/), a Karel-the-robot clone using Python > that I wrote. The robot's name in my version is Reeborg, hence the title > of this post. > > Since the last version was produced in 2009, RUR-PLE had been downloaded > more than 11,000 times. Since people that download it do not need to > contact me to do so, it is only through serependity that I find out where > it is used. I know that it has been used by elementary school children in > Austria, by high school children in New Jersey and by university students > in the U.S. and Latin America as a tool to introduce Python. > > Recently, Samsung contacted me and got my permission to produce a book > based on RUR-PLE. They distributed free copies of this book yesterday to > something like 1000 Korean students. (I will likely post pictures of the > book on my blog when I get a copy.) > > So what you say?.... > > I am happy to announce that a test-version of "Reeborg's world" is now > available online as a tool to learn Python. It is free to use and does > not require registration. > > The first version of Reeborg's world was produced to teach Javascript; it > is the default version available from http://reeborg.ca. It includes > some 98 lessons and can be found directly at > http://reeborg.ca/learn_js.html > > I'm working on an "improved" version which can be found at > http://reeborg.ca/learn_js_dev.html#welcome > Following some comments by early adopters, the UI of this version is > improved slightly and more changes are planned, including a graphical world > builder, new images for the robot, the option to import from file and save > to file programs and worlds, etc. > > The proof-of-concept Python version can be found at > http://reeborg.ca/learn_py_test.html > It is based on the "improved" version. I do not plan to do more work on it > (including adapting the lessons to teach Python instead of Javascript) > until I have nailed down the "improved" Javascript version. > > If you want to quickly try the Python version to see what it can do, I > suggest you select (from the drop down menu showing "Alone" by default) the > world "Tokens 1" and run the following program: > > move() > take() > move() > put() > move() > > I welcome any comments & suggestions about Reeborg's world; please feel > free to email me directly. > > This time, I will probably include a page on the site where I will ask > teachers that use it to communicate with me to let me know in what context > they use it, and keep track of it on a "wall of fame". > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Thu Mar 27 21:12:01 2014 From: kirby.urner at gmail.com (kirby urner) Date: Thu, 27 Mar 2014 13:12:01 -0700 Subject: [Edu-sig] What's a Callable? Message-ID: What's a callable? In making the transition from Algebra to a computer science friendly math class, such as many states have legislatively enabled (Oregon one such state), the distinction between "what's a callable" and "what's not" may feel familiar. Traditional math notation has to disambiguate between b * x, bx, b(x) and (b)(x), i.e. no operator at all between operands is taken to mean "multiplication". Few computer languages try to take it that far, but in reading (b)(x) it still helps to know if b is a "callable" or not, as if it is, then b(x) may be the evaluation strategy to employ. >>> def F(x): return x >>> (F)(3) 3 What I like about "callable" is one can identify a callable as having "a mouth" i.e. the parens form an emoticon-style sideways mouth, and that's the hallmark of any callable, whether they "eat arguments" or just "suck air". call_me(). Students know about emoticons, little sideways faces, so to associate "callable" with "emoticon" is anchoring and reinforcing. Then when you see the typically amateur use of parens: def F(x): return(2 + x) you can say: remember, return-the-keyword is not a callable; it has no mouth. return(2 + x) is not illegal but that's not a picture of return eating, that's a picture of (2 + x) putting on a belt or fencing itself in. 'return' does not eat, nor 'if', nor 'while'. Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Thu Mar 27 21:23:16 2014 From: kirby.urner at gmail.com (kirby urner) Date: Thu, 27 Mar 2014 13:23:16 -0700 Subject: [Edu-sig] reviewing the context manager construct In-Reply-To: References: Message-ID: """ Just for the Fun of It. [~tm] More in a similar vein.... These exercises may seem pretty pointless, but I remember coming from FoxPro to Python how excited I was by such long ints, then still a separate type from ints proper. The Decimal object had yet to join us back then. I feel programs below are like ritual welcoming ceremonies in that they show off the kinds of abilities our new circus animal brings to our circus. Apologies in advance for any unwanted wrapping. These give the idea but if you want to cut and paste / run, some tweaking may be in order to achieve runnability. A couple identities involving Phi: http://www.flickr.com/photos/kirbyurner/13432252025/ You might just want to show something these computers can do that a mere calculator cannot easily duplicate. These are "monster truck" decimals versus the abbreviated ones in most textbooks. """ digits = """1.61803398874989484820458683436563811772030917980576286213544862270526046281890 244970720720418939113748475408807538689175212663386222353693179318006076672635 443338908659593958290563832266131992829026788067520876689250171169620703222104 321626954862629631361443814975870122034080588795445474924618569536486444924104 432077134494704956584678850987433944221254487706647809158846074998871240076521 705751797883416625624940758906970400028121042762177111777805315317141011704666 599146697987317613560067087480710131795236894275219484353056783002287856997829 778347845878228911097625003026961561700250464338243776486102838312683303724292""".replace("\n","") import decimal with decimal.localcontext() as context: context.prec = len(digits)-1 phi = decimal.Decimal(digits) print(phi**2 + phi**-2) # Identity 1 (== 3) print(8 * phi**2 - phi**6) # Identity 2 (== 3) # and so they equal each other, see Flickr comments for more # http://www.flickr.com/photos/kirbyurner/13432252025/ (DK = David Koski) OUTPUT: 2.9999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999 8 3.0000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000002 On Tue, Mar 4, 2014 at 7:23 PM, Kirby Urner wrote: > """ > Just for Fun > > A quick sketch of a Context Manager construct. > > A context manager is a type instance with an > __enter__ and __exit__ protocol, and designed > to work with a suite indented under a "with statement" > > (cc) Kirby Urner, MIT License > O'Reilly School of Technology > Sebastopol, CA > > With thanks to: > http://www.greatplay.net/uselessia/articles/e2-1000.html > """ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Fri Mar 28 14:04:55 2014 From: vernondcole at gmail.com (Vernon D. Cole) Date: Fri, 28 Mar 2014 14:04:55 +0100 Subject: [Edu-sig] reviewing the context manager construct Message-ID: You are working too hard in creating your string literal. The *Python Language Reference Manual* says: > 2.4.2. String literal concatenation Multiple adjacent string literals > (delimited by whitespace), possibly using different quoting conventions, > are allowed, and their meaning is the same as their concatenation. Thus, > "hello" 'world' is equivalent to "helloworld". This feature can be used > to reduce the number of backslashes needed, to split long strings > conveniently across long lines, [...] > Also, the output is hard to really comprehend. So, may I humbly submit... from __future__ import print_function > > digits = > "1.61803398874989484820458683436563811772030917980576286213544862270526046281890" > \ > "244970720720418939113748475408807538689175212663386222353693179318006076672635" > \ > "443338908659593958290563832266131992829026788067520876689250171169620703222104" > \ > "321626954862629631361443814975870122034080588795445474924618569536486444924104" > \ > "432077134494704956584678850987433944221254487706647809158846074998871240076521" > \ > "705751797883416625624940758906970400028121042762177111777805315317141011704666" > \ > "599146697987317613560067087480710131795236894275219484353056783002287856997829" > \ > > "778347845878228911097625003026961561700250464338243776486102838312683303724292" > > import decimal > > def compress_print(d): > s = str(d) > reps = 0 > digit = s[2] > i = 3 > while s[i] == digit: > i += 1 > reps += 1 > return '{} and {} more "{}"s then {}'.format(s[:3], reps, digit, s[i:]) > > with decimal.localcontext() as context: > context.prec = len(digits)-1 > phi = decimal.Decimal(digits) > id1 = phi**2 + phi**-2 # Identity 1 (== 3) > id2 = 8 * phi**2 - phi**6 # Identity 2 (== 3) > print('Phi is {} digits long, {}...{}'.format(len(digits) - 1, > digits[:5], digits[-5:])) > print('The 1st identity is', compress_print(id1)) > print('The 2nd identity is', compress_print(id2)) > print('Equal?', id1 == id2) > print('The difference is=', id2 - id1) > > Phi is 624 digits long, 1.618...24292 The 1st identity is 2.9 and 621 more "9"s then 8 The 2nd identity is 3.0 and 620 more "0"s then 2 Equal? False The difference is= 2.2E-622 -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Fri Mar 28 15:39:41 2014 From: kirby.urner at gmail.com (kirby urner) Date: Fri, 28 Mar 2014 07:39:41 -0700 Subject: [Edu-sig] reviewing the context manager construct In-Reply-To: References: Message-ID: On Fri, Mar 28, 2014 at 6:04 AM, Vernon D. Cole wrote: > You are working too hard in creating your string literal. > > The *Python Language Reference Manual* says: > >> 2.4.2. String literal concatenation Multiple adjacent string literals >> (delimited by whitespace), possibly using different quoting conventions, >> are allowed, and their meaning is the same as their concatenation. Thus, >> "hello" 'world' is equivalent to "helloworld". This feature can be used >> to reduce the number of backslashes needed, to split long strings >> conveniently across long lines, [...] >> > > Right, so no need for all those backslashes: digits = ("1." "61803398874989484820458683436563811772030917980576286213544862270526046281890" "244970720720418939113748475408807538689175212663386222353693179318006076672635" "443338908659593958290563832266131992829026788067520876689250171169620703222104" "321626954862629631361443814975870122034080588795445474924618569536486444924104" "432077134494704956584678850987433944221254487706647809158846074998871240076521" "705751797883416625624940758906970400028121042762177111777805315317141011704666" "599146697987317613560067087480710131795236894275219484353056783002287856997829" "778347845878228911097625003026961561700250464338243776486102838312683303724292") > Also, the output is hard to really comprehend. So, may I humbly submit... > > Thanks. Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From roberto03 at gmail.com Mon Mar 31 15:11:24 2014 From: roberto03 at gmail.com (roberto) Date: Mon, 31 Mar 2014 15:11:24 +0200 Subject: [Edu-sig] Parallel computing Message-ID: Hi, I recently finished setting up a Beowulf Cluster using some Linux machines at schools. Some students eagerly helped out. We'd like to start studying some parallel computing on this system. I already studied it on C but never on Python. My students regularly study Python, so I'd like to ask you if you taught some Python Parallel Computing to High School students and where to start from. Thank you very much -- Roberto -------------- next part -------------- An HTML attachment was scrubbed... URL: From john.zelle at wartburg.edu Mon Mar 31 15:17:04 2014 From: john.zelle at wartburg.edu (John Zelle) Date: Mon, 31 Mar 2014 13:17:04 +0000 Subject: [Edu-sig] Parallel computing In-Reply-To: References: Message-ID: <3EFB1CC619385749B99D8B4B22B243FA1D7DC108@MSEXCHMB01.wartburg.edu> We've had good luck in the past using pypar (http://code.google.com/p/pypar/) in a college scientific computing class for students who have had a single programming course in Python. At that time (2 years ago), it seemed to be the simplest entry point for Python-based MPI type programs. John Zelle, PhD Professor of Computer Science Wartburg College ________________________________ From: Edu-sig [edu-sig-bounces+john.zelle=wartburg.edu at python.org] on behalf of roberto [roberto03 at gmail.com] Sent: Monday, March 31, 2014 8:11 AM To: edu-sig at python.org Subject: [Edu-sig] Parallel computing Hi, I recently finished setting up a Beowulf Cluster using some Linux machines at schools. Some students eagerly helped out. We'd like to start studying some parallel computing on this system. I already studied it on C but never on Python. My students regularly study Python, so I'd like to ask you if you taught some Python Parallel Computing to High School students and where to start from. Thank you very much -- Roberto -------------- next part -------------- An HTML attachment was scrubbed... URL: From roberto03 at gmail.com Mon Mar 31 20:47:43 2014 From: roberto03 at gmail.com (roberto) Date: Mon, 31 Mar 2014 20:47:43 +0200 Subject: [Edu-sig] Parallel computing In-Reply-To: <3EFB1CC619385749B99D8B4B22B243FA1D7DC108@MSEXCHMB01.wartburg.edu> References: <3EFB1CC619385749B99D8B4B22B243FA1D7DC108@MSEXCHMB01.wartburg.edu> Message-ID: Thank you very much. Roberto On Mon, Mar 31, 2014 at 3:17 PM, John Zelle wrote: > We've had good luck in the past using pypar ( > http://code.google.com/p/pypar/) in a college scientific computing class > for students who have had a single programming course in Python. At that > time (2 years ago), it seemed to be the simplest entry point for > Python-based MPI type programs. > > John Zelle, PhD > Professor of Computer Science > Wartburg College > > ------------------------------ > *From:* Edu-sig [edu-sig-bounces+john.zelle=wartburg.edu at python.org] on > behalf of roberto [roberto03 at gmail.com] > *Sent:* Monday, March 31, 2014 8:11 AM > *To:* edu-sig at python.org > *Subject:* [Edu-sig] Parallel computing > > Hi, I recently finished setting up a Beowulf Cluster using some Linux > machines at schools. > Some students eagerly helped out. > > We'd like to start studying some parallel computing on this system. > I already studied it on C but never on Python. My students regularly study > Python, so I'd like to ask you if you taught some Python Parallel Computing > to High School students and where to start from. > > Thank you very much > > -- > Roberto > -- Roberto -------------- next part -------------- An HTML attachment was scrubbed... URL: From calcpage at aol.com Mon Mar 31 23:54:53 2014 From: calcpage at aol.com (A. Jorge Garcia) Date: Mon, 31 Mar 2014 17:54:53 -0400 (EDT) Subject: [Edu-sig] Parallel computing In-Reply-To: References: Message-ID: <8D11B42FB3577EE-D94-F2E0@webmail-vd011.sysops.aol.com> I have used MPI4PY implemented on this bootable Linux CD http://pareto.uab.es/mcreel/PelicanHPC Burn one CD, reboot your whole classroom in minutes with an MPI environment via PXE boot. HTH, A. Jorge Garcia Applied Math, Physics & CS http://shadowfaxrant.blogspot.com http://www.youtube.com/calcpage2009 2013 NYS Secondary Math http://PAEMST.org Nominee