Hi Volker,

On Thu, Nov 08, 2012 at 08:02:49AM -0800, Volker Braun wrote:
>    This occurred to me before, its nice to have iterators/generators but
>    there should be a mechanism to say that the iterator is over a finite or
>    infinite set.
>    Just to avoid doing exhaustive searches over infinite sets.
>    Similar to C++ iterator traits, I guess. Of course if you were to manually
>    implement a generator as a Python class (implementing __next__) you could
>    attach other methods like is_finite(). But then you'd always have to write
>    a lot of boilerplate to return an iterator. Its much easier to use yield,
>    but then you can't return any additional information about finiteness. 
>    The alternative is to assume that the user knows what he is doing when he
>    passes an iterator / generator object. V.sum(W) can and should still check
>    that W is finite before starting to iterate over W.

There is already a bit of infrastructure for this; namely an parent
modeling an enumerated set which is infinite should declare itself in
the category InfiniteEnumeratedSets (soon to come: Sets().Infinite()).
Then, methods could do some checks on this; that's already the case
for e.g. ``list``::

    sage: ZZ.list()
    Traceback (most recent call last):
    ...
    ValueError: since it is infinite, cannot list Integer Ring

Of course a preliminary step would be to make sure that parents are
put in this category when relevant. Here QQ^3 should not only be an
iterable but actually an infinite enumerated set:

    sage: (QQ^3) in InfiniteEnumeratedSets()   # todo: not implemented
    True

More precisely: QQ^3 should be in the category of finite dimensional
modules with basis, and a finite dimensional module with basis over an
infinite field should be in the category of infinite enumerated sets.

Cheers,
                                Nicolas
--
Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net>
http://Nicolas.Thiery.name/

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To post to this group, send email to sage-devel@googlegroups.com.
To unsubscribe from this group, send email to 
sage-devel+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.


Reply via email to