Thanks for the detailed explanation -- answering all points except
"Why the s in srange?"!

John

On 22/01/2008, Carl Witty <[EMAIL PROTECTED]> wrote:
>
> On Jan 22, 1:31 am, Paul Zimmermann <[EMAIL PROTECTED]> wrote:
> > I also "enjoyed" several times converting from 'int' to 'Integer' and back.
> > For beginners, this is a real difficulty, and in my opinion range? or 
> > xrange?
> > should give a big warning that the "list of integers" output contains Python
> > integers, which cannot be mixed with SAGE integers 'Integer'.
> >
> > It would also be nice to have a pointer from range? to srange (which does
> > mention the difference between SAGE integers and Python int's).
> >
> > Finally, is there a valid reason why we have both 'int' and 'Integer'?
> > (The 'int' type does not seem to have any size limitation.)
>
> The 'int' (and its bignum counterpart, 'long') are native Python
> types.  As far as I know, we don't modify Python at all; removing
> 'int' would be major surgery, and we're not going to do it.
>
> 'Integer' is a Sage type.  This means it has lots of useful
> mathematical convenience methods (like .is_square()), it participates
> in the coercion model, etc.  Also, 'Integer' is implemented with GMP,
> and 'long' is not, so 'Integer' is much faster for large numbers.
>
> range() and xrange() are Python builtins, so they return Python values
> ('int' or 'long'), and have documentation that doesn't mention any
> other types.  srange() was written for Sage.
>
> The final state of affairs, where we have multiple integral types that
> show up in different contexts, is certainly annoying; but I don't see
> how to avoid it while basing Sage on an unmodified Python; and we get
> so much benefit from that decision that I wouldn't want to change it.
>
> Some particular annoyances may be fixable.  For instance, you can just
> do:
>
> sage: range=srange
>
> to overwrite Python's built-in range with Sage's for the current
> command-line session.  I suppose we could do that globally on Sage
> startup; but 1) this might break other Python code that expects to use
> the original range(); and 2) I'm not sure we want to go down the path
> of modifying Python's behavior, other than the preparser.
>
> Carl
>
> >
>


-- 
John Cremona

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@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-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to