Hi Ralf,

On 2018-03-27, Ralf Stephan <gtrw...@gmail.com> wrote:
> sage: (2^23+1)/3
> 2796203
> sage: _.is_prime()
> False
> sage: factor(2796203)
> 2796203
>
> It turns out that Rational.is_prime does not exist and the fallback gives 
> false answers.

My first association: We should change the printed form of a rational
number. The integer 2796203 should print as 2796203, but the
corresponding rational number should be printed as 2796203/1.

In that way, if a user copy-and-pastes printed output back into Sage,
there won't be a confusion between integers and rationals.

I know that it is hardly possible to achieve that pasting of printed
output will ALWAYS create a copy of the printed object. However, in
cases where it is easily possible (the real number 1 should print as
1.0, the rational number 1 should print as 1/1, the complex number 1
should print as 1.0+0.0*I etc), we should do it.

My second association: The fallback of is_prime should print a clear warning
in the case that the input's parent is a field. Such as:
  WARNING: The given number is defined as element of <self.parent()>,
  which is a field. There are no prime numbers in a field, so, probably
  you want to convert the number into <self.parent().ring_of_integers()>.

It might be good to add an optional argument to the method that allows to
switch the warning off.

> Then, I tried to print a list of primes of the above form, using the global 
> is_prime:
>
> sage: for n in range(1,100):
> ....:     if is_prime((2^n - (-1)^n)/3):
> ....:         print((2^n - (-1)^n)/3)
> ....:         
> sage:
>
> No output. Turns out `is_prime(ZZ((2^n - (-1)^n)/3))` works. Really? How 
> long does Sage exist without a fix to that?

I suppose you are aware that from a maths point of view it isn't a bug,
since your code is (implicitly!) asking for prime numbers in QQ.

However, I agree that it is (for most users) unintended behaviour, and
as a corollary to "explicit is better than implicit", we have "implicit
is not as good as explicit".

I believe, when mathematically sound behaviour of SageMath is very likely
not what a user wants, then printing a fat warning that can optionally
be switched off (as above) is the correct fix. Just don't raise an error,
and please do not change the function to give a mathematically wrong answer
((3/1).is_prime() returning "True" would be wrong).

Best regards,
Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to