On Feb 6, 2010, at 4:28 AM, Nicolas M. Thiery wrote:
On Sat, Feb 06, 2010 at 03:21:54AM -0800, Robert Bradshaw wrote:
It was just pure luck that it ever worked on any system... I agree
that an exception would be prettier, but the same parent => avoid
typechecks is an important optimization, especially for arithmetic
of basic types.
Just a quick rant. Here the thing is that we have an invariant for:
self.parent() = ZZ <=> self.__class__ = Integer
When some low-level method of IntegerRing / IntegerRing needs to
check
than an object is an integer, and don't want to test both,
wouldn't it
be safer (and as fast?) to test that the class of the object is
Integer, and then assume that its parent is ZZ, rather than the
converse? That sounds safer to me, because breaking the assumption
requires doing something wrong with the class Integer, which is well
localized. Whereas any element far far away in user's code can
wrongly
set its parent to IntegerRing.
That wouldn't work because there is usually a many to one
relationship between parents and classes.
My suggestion was surely only for basic arithmetic types where speed
is an critical issue. For those, don't we have a one to one relation?
For a couple of types, like ZZ and QQ, yes. RR and CC support
different precision parents (and rounding modes), and of course Z/nZ
is pretty basic (and should be insanely fast). The code path in
question here is the very top-level check in binary operations, where
if the Parent is the same we assume we can get directly to work.
Specific classes can do their own typechecking there if they feel its
necessary (that would be hard to do generically anyways).
Perhaps a better way to phrase the implicit assumption is that an
Element knows about all possible other Elements with the same parent.
- Robert
--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org