Hi Vincent,
Recently when playing around with standard tableaux, which are enumerated
sets, I rewrote their getitem methods because I thought that they should
support slices. At the time I thought that this should go into the
enumerated set code but I wasn't sure where to put it. Modulo the
documentation, __getitem__ for the standard tableaux classes now looks like
this:"
def __getitem__(self, r):
if isinstance(r,(int,Integer)):
return self.unrank(r)
elif isinstance(r,slice):
start=0 if r.start is None else r.start
stop=r.stop
if stop is None and not self.is_finite():
raise ValueError, 'infinite set'
else:
raise ValueError, 'r must be an integer or a slice'
count=0
tabs=[]
for t in self:
if count==stop:
break
if count>=start:
tabs.append(t)
count+=1
# this is to cope with empty slices endpoints like [:6] or [:]
if count==stop or stop is None:
return tabs
raise IndexError, 'value out of range'
I don't know whether this is generally thought to be a good idea, but I
like being able to write things like:
sage: StandardTableaux(40)[0:10]
Btw, I also think that the InfiniteEnumeratedSet and FiniteEnumerated set
categories should define an is_finite() method which returns False and
True, respectively. As far as I could see, there is no easy way to ask them
whether they are finite or infinite.
If people agree that these are good features I'd be happy to look after it
-- if someone can tell me where the code should go, this wasn't so obvious
to me.
Andrew
On Sunday, 19 August 2012 02:54:23 UTC+10, Vincent Delecroix wrote:
>
> Hello,
>
> This message is especially intended to Florent and Nicolas B. I
> modified a bit FiniteEnumeratedSet and IntegerRange for the ticket
> 8920 that unify alphabet with sets. The main changes are
> * "int(2) in IntegerRange(0,10)" now answers True
> * the representation string of IntegerRange is a bit modified
> * I created methods rank/unrank/random_element for FiniteEnumeratedSet
> If any modification is bad for you please say it on the trac ticket.
>
> Best,
> Vincent
>
--
You received this message because you are subscribed to the Google Groups
"sage-combinat-devel" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sage-combinat-devel/-/qU0eAguVdOcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-combinat-devel?hl=en.