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 -1
> sage: l
> 4
> sage: range(5)[l]
> 4


The error message could have been more informative also.

Thanks again,
Nikos

On Thu, Jan 21, 2021 at 9:28 AM Vincent Delecroix <20100.delecr...@gmail.com>
wrote:

> 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
> .
>


-- 
Οι ελαφροί ας με λέγουν ελαφρόν.
Στα σοβαρά πράγματα ήμουν πάντοτε
επιμελέστατος.

The frivolous can call me frivolous. In serious matters I've always been
most diligent.
  K. P. Kavafy

-- 
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/CAO2SUmJdVkSoF66caRF-GXpd9AqLHwvGOaCnnw%3DbWZXGrR-tJw%40mail.gmail.com.

Reply via email to