Please help me follow you : You want to define a + and * operatorsfor Combinations, in such a way that Combination.sum() is not necessary anymore, which in turn means that sum(Combination([1,2,3])) would return 6 ?
Nathann On 20 May 2014 10:16, Simon King <simon.k...@uni-jena.de> wrote: > Hi Nicolas, > > On 2014-05-19, Nicolas M. Thiery <nicolas.thi...@u-psud.fr> wrote: > > On Mon, May 19, 2014 at 04:01:52PM +0000, Simon King wrote: > >> Multiplication? I always think of words as elements of a free group, of > >> course multiplicatively written. Hence, concatenation of words w1,...,wn > >> would be prod([w1,w2,...,wn]). > > > > Indeed. > > > > `+` works too for concatenation of words, which is consistent with > > Python strings. But sum does not. Oh well. > > The reason is that the sum(...) function starts the summation with > zero, unless told to be differently. However, 0 is not coerced to the > empy word, or to strings for that matter. If it would, summation would > work. > sage: W = Words(range(27)) > sage: a = W([randint(0,26) for _ in range(10)]) > sage: sum([a,a,a]) > <BOOM> > TypeError: unsupported operand type(s) for +: 'int' and > 'FiniteWord_list' > sage: sum([a,a,a],a) > word: > > 20,17,5,14,2,14,5,9,4,21,20,17,5,14,2,14,5,9,4,21,20,17,5,14,2,14,5,9,4,21,20,17,5,14,2,14,5,9,4,21 > sage: sum(['a','a','a']) > <BOOM> > TypeError: unsupported operand type(s) for +: 'int' and 'str' > sage: sum(['a','a','a'],'a') > <BOOM> # O dear... > TypeError: sum() can't sum strings [use ''.join(seq) instead] > > Nonetheless, I think multiplicative notation should be enabled as well, > as a courtesy to group theorists... > > But it is all not easy. I stated above, one should coerce 0 to the empty > word. But then, written multiplicatively, one would coerce 1 to the > empty word as well. Not very nice. Specifically if you really think of > words being additive, and 5*a should be a+a+a+a+a, and not empty_word*a. > > Perhaps one should better say that W has a single operator (either + or *, > but not both), and if + is chosen, then 5+a should not be defined, but > 5*a should be a+a+a+a+a. Or if * is chosen, then 5+a and 5*a should not > be defined, but a^5 should be it. In other words, one shouldn't try to > coerce NN into W, but one should think of W as endowed with an NN > action. And at the end of the day, I'd say that sum([a,a,a]) is a misuse > of the sum() function. > > Best regards, > Simon > > > > > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sage-combinat-devel" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sage-combinat-devel/PDPkJc_PBSE/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > sage-combinat-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-combinat-devel@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-combinat-devel. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-combinat-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-combinat-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-combinat-devel. For more options, visit https://groups.google.com/d/optout.