[Edu-sig] re: Python Programming: An Introduction to ComputerScience

Kirby Urner urnerk at qwest.net
Sun Dec 14 14:38:33 EST 2003


> I think teaching math and programming is a very interesting idea ...
> proofs are just a kind of code walkthrough.
> 
> Toby
> --

In my own case, I've thought less about proofs and more about using programs
to demonstrate what a proof means/says (i.e. what's asserted, before you
even prove it).

I understand Jeff's point that lots of kids dislike mathematics and bringing
more math into programming might be a sure way to kill it -- takes all the
fun out.

But he also sees the flip side of the equation, which is we have the
opportunity to take a somewhat unpopular subject (math) and enliven it with
a command line such as Python's.

An example I like is polynomials (usually a big topic in algebra).  You get
to see that there's a kind of positional notation, as with decimal numbers,
where the positions correspond to 'degree' i.e. x**0, x**1, x**2 and so on.

So Poly([1,2,-3]) would be a way to instantiate 1 + 2*(x**1) - 3*(x**2).

Then using __call__, you can actually pass in some value for x, e.g.:

  >>> p1 = Poly([1,2,-3])
  >>> p1
  1 + 2*(x**1) - 3*(x**2)
  >>> p1(5)
  -64

With this framework in place, we'd now like to define __add__, __sub__, and
__mul__ so that we might go:

  >>> p2 = Poly([0,0,1])
  >>> p1 + p2
  1 + 2*(x**1) - 2*(x**2)
  >>> p3 = p1 * p2
  >>> p3
  (x**2) + 2*(x**3) - 3*(x**4)

In coding the guts of polynomial addition and multiplication, you learn
quite a bit about programming, and polynomials, at the same time.

And it's remarkable how little Python code it takes to implement all of the
above.

And as I mentioned earlier, I think it really pays off to develop a Vector
class in Python, complete with operator overloading.  I did this with 13
year olds in conjunction with POV-Ray.  They remained open minded and
pleased with the topic, even though it was way above grade level, because it
was presented in a context that was interesting to them.

http://www.4dsolutions.net/ocn/pygeom.html is where I've archived materials
from this course (now complete).

Kirby





More information about the Edu-sig mailing list