[Edu-sig] Natural Language Programming
Kirby Urner
pdx4d@teleport.com
Thu, 11 Jan 2001 08:41:25 -0800
>But to put my money where my mouth is, it was only
>interesting to me to the extent I could tie it to some
>recognized geometric notation.
With regard to vectors, it's already standard.
v1 + v2 are two "arrows" adding tip-to-tail, with
v3 being the "new arrow" straight to where you end
up. Here's a simple class for just doing vector
addition (nothing else) -- I know you know this stuff
but I was just sharing it with a math teacher so I'm
getting double-duty via cut 'n paste...
>>> from operator import *
>>> class vector:
def __init__(self, coords):
self.xyz = coords
def __add__(self, v):
return vector(map(add,self.xyz,v.xyz))
>>> v1 = vector((1,2,3))
>>> v2 = vector((4,5,6))
>>> v3 = v1 + v2
>>> v3.xyz
[5, 7, 9]
Then I wrote (to the math teacher):
"This shows me defining a class right at the >>> command line,
but of course it's more practical to write such things in
the full screen editor and import, e.g.
>>> from mymodule import vector
Students gradually build up their modules as they learn
about vector addition (all I've shown so far), scalar
multiplication, dot and cross product. What's cool is
by defining __add__, we're overriding the + sign, so
that we can actually use + in a new way, as an operator
related to vector objects.
Dunno, for some reason that's just the bee's knees as
far as I'm concerned."
What I take up in my little paper (recent) is how you
can hyperlink to SIGMA notation (greek letter SIGMA)
and go: def sigma(vlist): return reduce(add,vlist)
to get a vector sum of lots of vectors (vlist is a
list of vectors).
Note: in my geometry programs, when you want an edge
between any two points, it's
>>> edge(v1,v2)
And when you want a face (polygon) it's
>>> face([v1,v2...vn])
I don't have any lines or planes of so-called "infinite"
extent. Having those would be challenging, and I think
you've done that in PyGeo somehow.
Kirby
PS: a math teacher dinking around with Python on the
side on his school Mac confirms that the Mac IDLE has no
color coding of key words. If there's an innovation
I think'd make a difference to Python in the schools,
it'd be duplicating Windows/Linux colorizing of key
words on the Mac. Maybe a Tk issue? I know Guido's
bro has a lot to do with the Mac version of IDLE.
Wondering if there's a plan...