Dear Nils, Thanks for the useful suggestions.
I probably used the wrong terminology, coercion vs conversion, sorry. What I meant is simply that almost everywhere on Sage 8/2 is accepted as input to a function that takes integer arguments, as it should IMHO. I understand that preprocessing arguments in general may lead to trouble but 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. Best, Nikos On Sun, Jan 24, 2021 at 6:14 PM Nils Bruin <nbr...@sfu.ca> wrote: > On Thursday, January 21, 2021 at 7:21:52 AM UTC-8 Nikos Apostolakis wrote: > >> 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 >> >> >> There's a subtle difference here: The python interface here requires an > index to be something that can be converted into an integer; i.e., > something for which the __int__ method does the right thing. "Coercion" in > sage has a more restricted notion; see the docs. In sage, there is no > coercion from QQ to ZZ, because there is no natural map from one to the > other. There is a conversion, though, which is allowed to be a partial map. > > Generally, coercion maps only exist in one direction. Otherwise, things > like ZZ(1)+QQ(2) whould have an ill-determined type. > > Whether "Words" should attempt to convert its second argument to an > integer is a different matter. Generally it is best to start interface > design by doing only a minimal amount of processing to the argument, > because being "smart" for one thing can easily hide errors in another case. > > The error message that is currently given is perhaps a little generic, but > it does clearly indicate that the arguments given to "Words" are > problematic. Once you check that the *apparent* arguments work fine if > entered directly, it's clear there's probably a type issue. If you use > IPython's interactive debugger ("%debug") you can dive into the problematic > code and query the arguments and their types directly, within the context > where the error was raised. That can be a big time saver, because it can > help you find the error without having to construct a stand-alone > reproducible test case that you would need if you want to communicate the > error to other people. > > -- > 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/01a9d1dc-c402-444e-81c8-e8aa86b2945an%40googlegroups.com > <https://groups.google.com/d/msgid/sage-support/01a9d1dc-c402-444e-81c8-e8aa86b2945an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Οι ελαφροί ας με λέγουν ελαφρόν. Στα σοβαρά πράγματα ήμουν πάντοτε επιμελέστατος. 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/CAO2SUmLbq39SE4oqj%3DC1mC5Xwo4Led%2BO9vEUcpLjobebDEAr0w%40mail.gmail.com.