Hello,
I want to know the best practices for extending the functionality of a sage
class. For example, I would like to add the following method to the
Partition class in sage:
#\lambda^(i) from Carrell-Goulding paper
def i_part(self,i):
if i==0:
return self
elif i<0:
return (self.conjugate().i_part(-i)).conjugate()
zero_one_sequence = self.zero_one_sequence()
num_ones = zero_one_sequence.count(1)
if num_ones < i:
zero_one_sequence += (i-num_ones)*[1]
index_one_list = [index for index in range(len(zero_one_sequence)) if
zero_one_sequence[index] == 1]
zero_one_sequence[index_one_list[i-1]]=0
return Partitions().from_zero_one(zero_one_sequence)
My first inclination is to subclass Partition and add this as a method to
the subclass. However, I am not able to make this work.
So what I have done so far is to just include the above function definition
in a module followed by the following line:
Partition.i_part = i_part
So I am dynamically changing the Partition class. This doesn't seem like a
good practice in general, so I would like to know what is the preferred
solution.
Dinakar
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.