I definitely believe that a good way to improve our current math curriculum would be to weave in computational number theory. This would be the 21st century answer to 'back to basics'. <br><br>I think a huge problem in student math illiteracy has to do with not understanding division, remainders, and ratios. When dealing with division, our curriculum tends to focus on quotients, but understanding the nature of the remainder has a lot to do with what math and technology are about these days.<br>
<br>Exploring how to find primes is definitely a 'must include' in a computational math curriculum. I think students should explore this in a variety of ways, including both sieves and generators, discussing why one might choose one approach or another in various situations. This would do a whole lot of good for both math and tech literacy simultaneously.<br>
<br>An interesting fact is that, except for 2 and 3, all primes are adjacent to a multiple of 6. That is easy to prove:<br><br> Let n be a multiple of 6.<br> n+1 might be prime.<br> n+2 is divisible by 2.<br> n+3 is divisible by 3.<br>
n+4 is divisible by 2.<br> n+5 might be prime<br> n+6 is another multiple of 6.<br><br>Here's a generator that uses this jumping by 6 approach:<br><br>def primes():<br> p = [-1, 2, 3]<br> for x in p: yield x<br>
def is_prime(n):<br> for factor in p[1:]:<br> if factor**2 > n: return True<br> if n%factor == 0: return False<br> multiple = 6<br> while True:<br> if is_prime(multiple-1): yield multiple-1; p.append(multiple-1)<br>
if is_prime(multiple+1): yield multiple + 1; p.append(multiple+1)<br> multiple += 6<br><br>- Michel<br><br><div class="gmail_quote">On Sat, Jan 17, 2009 at 9:31 PM, kirby urner <span dir="ltr"><<a href="mailto:kirby.urner@gmail.com">kirby.urner@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">On Sat, Jan 17, 2009 at 5:40 PM, Gregor Lingl <<a href="mailto:gregor.lingl@aon.at">gregor.lingl@aon.at</a>> wrote:<br>
><br>
><br>
> kirby urner schrieb:<br>
>><br>
>> Yes thank you I completely agree. A stash of sieves, plus data mine<br>
>> this very archive for our earlier work on this topic.<br>
>><br>
>> My only suggestion is you include a generator version e.g.:<br>
>><br>
><br>
> At first this seems an attractive idea, but in my opinion the<br>
> idea of sieves is fairly antagonistic to that of generators.<br>
> A sieve is used to eliminate from a given set elements<br>
> that have not some desired property, while generators<br>
> (ideally) create objects, one at atime, with that desired<br>
> property. Drastically: you cannot sieve at first all even<br>
> numbers from an infinite set or sequence. For educational<br>
> purposes I'd prefer examples that display a single concept<br>
> in a small and simple way. :-* A prime number generater<br>
> based on some different algorithm of course may be<br>
> interesting and useful.<br>
<br>
</div>Yes sir! Excellent clarification. The goal is to have a worthy<br>
generator that always gives the next prime. "Trial by division" is<br>
the simplest approach I can think of...<br>
<br>
>>> def primes():<br>
sofar = [-1, 2,3] # a running start, -1 proposed by J.H. Conway<br>
yield sofar[0] # get these out of the way<br>
yield sofar[1] # the only even prime<br>
yield sofar[2] # and then 3<br>
candidate = 5 # we'll increment from here on<br>
while True: # go forever<br>
for factor in sofar[1:]: # skip -1 (or don't use it in the first place)<br>
if factor ** 2 > candidate: # did we pass?<br>
yield candidate # woo hoo!<br>
sofar.append(candidate) # keep the gold<br>
break # onward!<br>
if not candidate % factor: # oops, no remainder<br>
break # this is a composite<br>
candidate += 2 # next odd number please<br>
<div class="Ih2E3d"><br>
<br>
>>> g = primes()<br>
>>> next(g)<br>
-1<br>
>>> next(g)<br>
</div><div class="Ih2E3d">2<br>
>>> next(g)<br>
3<br>
>>> next(g)<br>
5<br>
</div>>>> next(g)<br>
7<br>
>>> next(g)<br>
11<br>
>>> next(g)<br>
13<br>
>>> next(g)<br>
17<br>
>>> next(g)<br>
19<br>
>>> next(g)<br>
23<br>
>>> next(g)<br>
29<br>
>>> next(g)<br>
31<br>
>>> next(g)<br>
37<br>
>>> next(g)<br>
41<br>
<br>
I think you're correct that the sieve best works with a pre-specified<br>
finite domain: sieve it completely, using divisors <<br>
math.sqrt(len(domain)) then iterate over it maybe, but the array is<br>
already populated, taking up memory. The above generator, in<br>
contrast, gradually takes up more memory (shows what generators are<br>
good for then: saving state between cycles).<br>
<div class="Ih2E3d"><br>
> To continue work in this area one (or at least me) has to have<br>
> some criteria to judge the solutions.<br>
> Clearly it was advantageous if there was some consensus about<br>
> these criteria in the community.<br>
<br>
</div>Fortunately, we have hundreds of years of math pedagogy, so in terms<br>
of avoiding quarrels, start with what's already on the books are "must<br>
have" and just render it Pythonically.<br>
<br>
So, for example, every pre-college math curriculum I'm aware of makes<br>
the distinction between prime and composite numbers.<br>
<br>
On the other hand, few include the Fermat test or Fermat's Little<br>
Theorem, don't have RSA as a goal. So whereas generators for primes,<br>
fibonaccis, pascal's triangle, would seem non-controversial, anything<br>
having to do with Fermat's Little Theorem would seem an uphill battle,<br>
especially without buy in on the RSA bit.<br>
<br>
What makes a lot of this stuff more accessible than before is we have<br>
the ability to work with large numbers of digits. Both text books and<br>
calculators tend to crap out at more that 15 significant figures. Not<br>
so in Python or any significantly endowed language. 2 ** 10000 is no<br>
problem for us, is for the paper and pencil crowd, or the TI crowd<br>
(both pitiable).<br>
<br>
I don't think there's a way to avoid quarrels. People have different<br>
leadings, throw their hats in the ring, and we see what synergies<br>
develop. My goal is to keep the process open and participatory, not<br>
to close it down. The sight of people debating is far less disturbing<br>
than the sight of everyone in lockstep (the Borg).<br>
<div class="Ih2E3d"><br>
><br>
> There should be some criteria concerning<br>
> (a) the choice of problems and themes,<br>
> e.g. to prefer small problems that expose a single idea - or rather not<br>
> ... etc.,<br>
> as well as some<br>
> (b) code related criteria, like clarity, conciseness, efficiency, beauty (!)<br>
> etc., ranked according to<br>
> their priorities.<br>
<br>
</div>This will be up to each professional teacher in whatever walk of life<br>
-- to judge what to include and what to exclude. Each teacher will<br>
find her or himself in agreement with some, disagreement with others,<br>
over what to include. Twas ever thus.<br>
<br>
What to avoid, in my book, is a restrictive environment which takes a<br>
one size fits all approach and dictates to all teachers how it must<br>
be, removing much individual freedom.<br>
<br>
Reduction in biodiversity is dangerous in my estimation.<br>
<br>
That's why I fight against "national curriculum" ideologues on the<br>
Math Forum, other places.<br>
<div class="Ih2E3d"><br>
> Once I had the following idea: there are so many renowned pythonistas<br>
> in the developers community, many of them also interested to promote<br>
> Python in the educational area (see for instance the protagonists in<br>
> Jeffrey Elkners "Introducing Python"). How about to ask them to make<br>
> a personal donation to the educators and learners: a piece of code,<br>
> 10 to 12 lines at most, that they individually consider to show most<br>
> convincingly the power or the beauty of programming with Python -<br>
> or the fun they have with it. Young people like role models ;-)<br>
><br>
<br>
</div>That's a fun idea.<br>
<br>
Another approach is to start some schools in which Python is defacto<br>
included as an important tool in the math curriculum, and compete with<br>
other schools that make different choices, see how that goes.<br>
<br>
Don't try to "convince the world" before starting your experiment.<br>
<br>
You need no one's permission to take the initiative.<br>
<br>
Individuals make all the difference in this world, alone and in groups.<br>
<div class="Ih2E3d"><br>
> Regrettably I didn't persue that idea further. What do you think of it. Ok,<br>
> the days of the early pioneers are over, but perhaps it's still worth a try?<br>
><br>
<br>
</div>I think the first generation of Pythoneers, counting myself as one of<br>
them, should be collecting momentos and souvenirs, as soon enough our<br>
generation will no longer be heard from, in terms of contributing new<br>
material.<br>
<br>
Your idea reminds me of the recipe book they made for Bucky Fuller,<br>
his many friends contributing their favorites.<br>
<br>
Looking back at 2008, random geek viewpoint:<br>
<a href="http://www.iht.com/articles/2008/12/22/arts/design22.php" target="_blank">http://www.iht.com/articles/2008/12/22/arts/design22.php</a><br>
<font color="#888888"><br>
Kirby<br>
</font><div><div></div><div class="Wj3C7c"><br>
<br>
> Regards,<br>
> Gregor<br>
><br>
><br>
><br>
><br>
><br>
>><br>
>> Using Python 3:<br>
>><br>
>><br>
>>>>><br>
>>>>> g = Primes()<br>
>>>>> next(g)<br>
>>>>><br>
>><br>
>> -1<br>
>><br>
>>>>><br>
>>>>> next(g)<br>
>>>>><br>
>><br>
>> ....<br>
>><br>
><br>
</div></div></blockquote></div><br>