[Edu-sig] Pythonic Math must include...

kirby urner kirby.urner at gmail.com
Thu Jan 15 05:13:50 CET 2009


"Must include" would be like an intersection of many sets in a Venn Diagram,
where we all gave our favorite movies and a very few, such as 'Bagdad Cafe'
or 'Wendy and Lucy' or... proved common to us all (no suggesting those'd be
-- just personal favorites).

In this category, three candidates come to mind right away:

Guido's for the gcd:

def gcd(a,b):
    while b:
        a, b = b, a % b
    return a

Then two generics we've all seen many times, generators for Pascal's
Triangle and Fibonacci Sequence respectively:

def pascal():
    Pascal's Triangle **
    row = [1]
    while True:
        yield row
        row = [ a + b for a, b in zip( [0] + row, row + [0] ) ]


def fibonacci(a=0, b=1):
    while True:
        yield a
        a, b = a + b, a

IDLE 1.2.1
>>> from first_steps import *
>>> gcd(51, 34)
>>> g = pascal()
>>> g.next()
>>> g.next()
[1, 1]
>>> g.next()
[1, 2, 1]
>>> g.next()
[1, 3, 3, 1]
>>> f = fibonacci()
>>> f.next()
>>> f.next()
>>> f.next()
>>> f.next()
>>> f.next()
>>> f.next()

Check 'em out in kid-friendly Akbar font (derives from Matt Groening of
Simpsons fame): http://www.wobblymusic.com/groening/akbar.html


( feel free to link or embed in your gnu math website )

I'm not claiming these are the only ways to write these.  I do think it's a
feature, not a bug, that I'm eschewing recursion in all three.  Will get to
that later, maybe in Scheme just like the Scheme folks would prefer (big
lambda instead of little, which latter I saw put to good use at PPUG last
night, well attended (about 30)).



In terms of curriculum, these belong together for a host of reasons, not
just that we want students to use generators to explore On-Line Encyclopedia
of Integer Sequences type sequences.  Pascal's Triangle actually contains
Fibonaccis along successive diagonals but more important we're laying the
foundation for figurate and polyhedral ball packings ala The Book of
Numbers, Synergetics, other late 20th century distillations (of math and
philosophy respectively).  Fibonaccis converge to Phi i.e. (1 + math.sqrt(5)
)/2.  gcd will be critical in our relative primality checks, leading up to
Euler's Theorem thence RSA, per the review below (a literature search from
my cube at CubeSpace on Grand Ave):


Remember, every browser has SSL, using RSA for handshaking, so it's not like
we're giving them irrelevant info.  Number theory goes into every DirecTV
box thanks to NDS, other companies making use of this powerful public

You should understand, as a supermarket manager or museum administrator,
something about encryption, security, what's tough to the crack and what's
not.  The battle to make RSA public property was hard won, so it's not like
our public school system is eager to surrender it back to obscurity.
Student geek wannabes perk up at the thought of getting how this works, not
hard to show in Javascript and/or Python.  Makes school more interesting, to
be getting the low-down.

By the same token, corporate trainers not having the luxury of doing the
whole nine yards in our revamped grades 8-12, have the ability to excerpt
specific juicy parts for the walk of life they're in.

Our maths have a biological flavor, thanks to Spore, thanks to Sims.  We do
a Biotum class almost right away ("Hello World" is maybe part of it's
__repr__ ?).  I'm definitely tilting this towards the health professions,
just as I did our First Person Physics campaign (Dr. Bob Fuller or leader,
University of Nebraska emeritus).

The reason for using bizarre charactersets in the group theory piece is we
want to get their attention off numbers and onto something more generic,
could be pictograms, icons, pictures of vegetables...

Feedback welcome,


** http://www.flickr.com/photos/17157315@N00/3198473850/sizes/l/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20090114/c717638b/attachment.htm>

More information about the Edu-sig mailing list