# [Edu-sig] Functions & Generators (gnu math memo)

kirby urner kirby.urner at gmail.com
Tue Sep 26 20:52:52 CEST 2006

```Logo -> Squeakland ->...

Python:

Functions and Generators (build directly off algebra, no need to harp
on "variables", although most students will want a strong "types"
discussion, as their earlier math was probably very weak in this area,
especially around strings)

Building on the potential of Squeakland Creatures (the warmer fuzzier
objects of a younger day), we make a big deal of the "arguments mouth"
(except you don't really need arguments), i.e. those curved
parentheses are like lips (optional link to fish lips in FS Coupler
segment (not the same as Vesica Pices, though related)).**

Remember, DO NOT postpone Generators as an advanced topic.  Every
since lazy list comprehensions (another used of curvy parentheses),
earlier really, we've had good reasons for harping on Generators.
This will get students acclimated with the Namespace that is Python
(or metapython):  iterators, generators, callables, special names,
type, class.

Early Functions:
============
GCD
Totatives
Totient
Triangular Numbers
Tetrahedral Numbers
Cuboctal/Icosahedral Numbers

Curriculum context:

Difference between Composite and Prime, concept of Relatively Prime
(strangers). Leading to: Integers Modulo N groups, germutation groups,
polyhedrally defined symmetry groups.  Note that J has some primitives
for generating cyclic notation, which you could use to motivate the
need for a Python counterpart.

Early Generators:
=============
Triangular Numbers
Tetrahedral Numbers
Cuboctal/Icosahedral Numbers
Fibonacci Numbers
Mandelbrot Set decider (convergent or not?)

Curriculum context:

Growing sphere packings per my OSCON 2005 and London Knowledge Lab
presentations, i.e. divergence represented with polyhedral numbers ala
'Book of Numbers' (cites Martin Gardner), with volume expanding as a
3rd power rate of linear growth (expressed in the scale method of our
Polyhedron parent class).

Of course list comprehension syntax is used from the get go, per the
usual approach of using collection types to go over basic dot notation
(per my EuroPython 2005 presentation).

Followup (where to go from here):

Once we're good at writing functions and generators, it'll be easy to
define new classes, as methods are simply functions with a self
argument (a basis for object instrospection).  Remember the "two
passes":

First pass: treating the builtins as read-only givens (axiomatic)

Second pass: rolling our own, coding up a namespace (interactively,
with unit testing)

Plus we might get back to the warm fuzzies by this route, now feeling
more like puppetmasters or cartoon animators i.e. we *make* cartoons,
don't just watch them (multi-track editing isn't just for others to do
for us).

I'm signing and returning my gnu math teaching contract today.  If you
don't have a gig yet, hang in there.  Once our DVD libraries are
easier to come by, you'll be ready, having trained hard while waiting.
Maybe you'll do it with Ruby, if our Python seems "too noisey" a
language for you.

For more on Gnu Math (both Memos and Meanderings), search math-teach
at the Math Forum, a principal outlet and recruiting ground for us.
Or look for more private lists in your own local neighborhood (does
your town have a Wanderers chapter?).

Kirby
Gnu Math Teacher
Portland "open source capital" Oregon

Also check "focal points" in my Bizmo Diaries around this time, if new
to our curriculum and just trying to get some overview.  And no, you
don't have to be a snake charmer.  I'm relying on the other Open
Source language communities to spin their own distros.

** might be able to do something around teeth when treating of default
and/or optional arguments, per Tow Mater example.

Re Coupler "fish lips":
http://groups.yahoo.com/group/synergeo/message/29178
```