Hi Rob! On Tue, Dec 14, 2010 at 03:09:55PM -0800, Rob Beezer wrote: > Symptom: The following code would appear to run forever, since the > rationals define an iterator that never quits. > > QQ.list() > > I discovered this when I presumed that > > (QQ^2).list() > > would raise an error. It doesn't. So I patched the free module code > so the iterator producing module elements would raise an error for a > module over an infinite base ring. That very nearly passed all tests, > except it ran afoul of the category test suite. A doctest for sets > (in the Set_object_union class) constructs a vector space. To get a > generic element for testing the test suite would appear to build an > iterator and then grab the first element produced, so my fix broke > that. (This appears to be at > categories.enumerated_sets._an_element_from_iterator) > > It looks like structure.parent._list_from_iterator_cached is where > the first examples get stuck, at least that looks like the right place > when you read the code and that's part of the traceback when you use > ctrl-C. > > Options: > > 1. _list_from_iterator_cached could ask if self is infinite and if > so, fail. This would break the test suite too, I think. > > 2. The test suite framework needs to get an element by some other > process. For example, (QQ^2).an_element() did not break with my > patch. > > 3. Tough. You ought to check if a set is infinite before you try to > list it (and students should just learn to do that). > > 4. Something else. > > I've attached one failure of the test suite from my patch to the > module code, there were four very similar failures from the one test: > _test_an_element, _test_elements, _test_elements_eq, > _test_some_elements. The last error message is from my patch. > > I'd started this as: http://trac.sagemath.org/sage_trac/ticket/10470 > > I would prefer to have modules raise an error rather than just hang. > If desired, I can try to fix more fundamental situations, like > ZZ.list(). Comments and suggestions appreciated.
The list method from InfiniteEnumeratedSets() does just that. So here is a possible route: - There should be an InfiniteSets() category - QQ should be in this category - The list method from InfiniteEnumeratedSets() should be lifted to InfiniteSets() Shorter alternative: QQ could be in InfiniteEnumeratedSets(). But for which one of the possible enumerations? For the record, I am planning to work in the coming month(s?) on improving the category framework to support "variants" (see [1]); this should include InfiniteSets as a side product. Cheers, Nicolas [1] http://trac.sagemath.org/sage_trac/wiki/CategoriesRoadMap -- Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/ -- 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