On Sat, Jan 10, 2009 at 9:22 AM, Jason Grout <jason-s...@creativetrax.com> wrote: > > John H Palmieri wrote: >> sage: timeit('set(S).issubset(set(T))') >> >> gives me very similar times to the first option (all(s in T for s in >> S)). So if I start with Sage sets, I don't seem to gain much by >> converting back to python sets for this (not to mention that if S = Set >> (ZZ), then set(S) runs into problems...).
The Sage enumerated Set type is just a light wrapper around Python's "frozenset" type with more sage/mathematical semantics. Just delegate to that for implementing is_subset: sage: X = Set([1..10]) sage: Y = Set([1..20]) sage: X._Set_object__object.issubset(Y._Set_object__object) True sage: Y._Set_object__object.issubset(X._Set_object__object) False sage: timeit('X._Set_object__object.issubset(Y._Set_object__object)') 625 loops, best of 3: 2.07 µs per loop sage: X._Set_object__object frozenset([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) sage: type(X) <class 'sage.sets.set.Set_object_enumerated'> In the actual code for is_subset, you'll have self.__object instead of self._Set_object__object, since of course the above example uses the command line so __ methods are mangled. The one interesting wrinkle will be doing, e.g., sage: X.is_subset(Set(ZZ)) where the Y = Set(ZZ) isn't an enumerated set. There you have to check each X for membership in Y. -- William William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---