On Sep 18, 2007, at 11:22 AM, Jaap Spies wrote: > William Stein wrote: >> ---------- Forwarded message ---------- >> From: Peter Doyle (a Professor at Dartmouth) >> Date: Sep 18, 2007 10:32 AM >> Subject: Re: Calculus >> To: William Stein <[EMAIL PROTECTED]> >> >> Hi William, >> >>> There was a long thread on sage-devel about this: >>> >>> >> http://groups.google.com/group/sage-devel/browse_thread/thread/ >> 674e88887d0da278 >> >> Thanks for pointing out this thread. Regarding range(), I was struck >> by how the discussion turned to the question of basing ranges at 0 >> rather than 1. Having the default lower bound 0 actually doesn't >> bother me at all. The real problem as I see it is that in range >> (1,10) >> the upper bound isn't included. This can be justified in the case of >> range(10) by viewing 10 as telling not the upper bound, but the >> length >> of the list. But in range(1,10), 10 tells neither the length of the >> list nor the upper bound. Or rather, it's the upper bound for a >> half-open interval of integers, which is not the kind of convention >> that is going to be natural for mathematicians or calculus students. >> Mathematicians *could* have defined $\sum_{i=1}^{10}$ not to include >> the upper limit in the sum. Only that's just not how we do it. >> > > Why not define a new function srange (short for sagerange), > or redefine the existing srange function: > > def srange(a,b=None,step=1, include_endpoint=True): > > or something like that. > > See sage: srange?? > > Alternative: reuse xrange > this function will be removed from Python in Python3000.
One disadvantage of this is that include_endpoint=True takes much more time to write than "+1", and requires the same amount of knowledge. Perhaps one could have a function "full_range" that includes the endpoint. I still like the [a..b] notation that makes things totally obvious, and I am as surprised as Peter Doyle at the shift of topic of whether or not indices should be 0-based (which we don't have a choice about while sticking with Python). > > >> This is not to say that I think you necessarily have to make this >> addition to the preparser. I think using Python was an inspired >> decision, and is responsible for the fact that SAGE is so great. I >> can see why you would not want to deviate from it without a >> compelling >> reason. Not yet, anyway: Maybe after all the hackers have moved on >> to Ruby (and then Topaz, and then Tourmaline...), leaving Python >> (i.e., SAGE) to the mathematicians. >> > > Diamonds are forever! > > Jaap > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---