def randgoodword(m):
if m % 2 == 0:
print("We haven't implemented the even case yet. Come back later!")
return None
l = (m-1)/2 -1
ws = Words(m,l)
i = randrange(m^l)
return Word([m]) + ws[i]
randgoodword(11)
#==>
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-138-127de63ad022> in <module>
----> 1 randgoodword(Integer(11))
<ipython-input-126-912d8fec37b3> in randgoodword(m)
6
7 l = (m-Integer(1))/Integer(2) -Integer(1)
----> 8 ws = Words(m,l)
9
10 i = randrange(m**l)
~/packages/sage-9.2/local/lib/python3.8/site-packages/sage/combinat/words/words.py in Words(alphabet, length, finite, infinite)
109 return Words_n(FiniteWords(alphabet), length)
110
--> 111 raise ValueError("do not know how to make a combinatorial class of words from your input")
112
113
ValueError: do not know how to make a combinatorial class of words from your input
#<==
i = randrange(11^4); i #==> 3230
Word([11]) + Words(11, 4)[i] #==> word: 11,3,5,8,8
version() #==> 'SageMath version 9.2, Release Date: 2020-10-24'
sage: m = 11
sage: l = (m-1)/2 -1
sage: l
4
sage: range(5)[l]
4
--
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 sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/50b6b4d7-1bf3-7407-34a0-fc884ebe3772%40gmail.com.
Dear Vincent,Thank you very much, that fixes it.IMHO this is a bug though, or at least an inconsistent behavior. Most of the time Sage silently coerces things to the appropriate type so commands just work. For example:
sage: m = 11
sage: l = (m-1)/2 -1sage: l
4
sage: range(5)[l]
4
sage: 8/2 in ZZ
True
--
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 sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/01a9d1dc-c402-444e-81c8-e8aa86b2945an%40googlegroups.com.
Dear Nils,
[...] I think treating rational integers as integers is safe. Actually Sage does that
sage: 8/2 in ZZ
True
So to have a function with integer input throw an error when you feed it a rational integer, is surprising and counterintuitive. To me at least.
Ah right, Sage takes a rather liberal interpretation of "in" here: since the target is given, it's apparently read as "can 8/2 be converted to an integer". I'm neutral on what Words should do with its arguments.