Dear Nikos,

When you write code it is important to understand what part triggered
the error and reduce the error to the minimum. In your situation
you can reproduce the very same error with the three lines

sage: m = 11
sage: l = (m-1)/2 -1
sage: ws = Words(m,l)

In particular it has nothing to do with function call.

The problem here is that l has rational type as can be seen with

sage: type(l)
<class 'sage.rings.rational.Rational'>

And indeed the following one line produces the same errr

sage: Words(11, QQ(4))


When you divide two integers you obtain a rational number. If you
want integer type use // instead of /.

Best
Vincent

Le 21/01/2021 à 14:30, Nikos Apostolakis a écrit :
Dear list,

I want to construct a class of words and I get this error when I call Words
from a function:


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
#<==


If I do this manually in the command line it works:

i = randrange(11^4); i #==> 3230
Word([11]) + Words(11, 4)[i] #==> word: 11,3,5,8,8



What am I doing wrong?

version() #==> 'SageMath version 9.2, Release Date: 2020-10-24'


Thanks for any help,
Nikos


--
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+unsubscr...@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.

Reply via email to