In a recursive function, I use a dictionary (which contains the elements of
the expansion of the argument on another basis). Since each call to the
function needs the dictionary, I don't want the user to be forced to put
the dictionary as an argument (i.e. I want him to call to_pbw(elem) instead
of to_pbw(elem,{})). But I get a little confused between local and global
variables with the code below since the dictionary is not emptied when
needed (my function as the expected behavior only when I call
to_pbw(elem,{})).
Could anyone help me (provided my question is not unclear)?
Matthieu
def to_pbw(f,l=dict()):
from sage.combinat.words.finite_word import to_monoid_element
if f!= 0 * f.parent().one():
support = [to_word(i[1]) for i in list(f)]
min=support[0]
if len(support) > 1:
for word in support[1:len(support)-1]:
if min.lex_less(word):
min = word
coeff = list(f)[support.index(min)][0]
if min not in l.keys():
l[min]=coeff
else:
l[min] += coeff
remainder = f - coeff * pbw_element(to_monoid_element(min))
return to_pbw(remainder,l)
return l
--
You received this message because you are subscribed to the Google Groups
"sage-devel" 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-devel.
For more options, visit https://groups.google.com/groups/opt_out.