On 27/03/2018 10:05, Simon King wrote:
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.
In plenty of CAS/python packages the difference is indeed explicit and I
think that it is helpful to understand what is happening. And it would
be helpful that copy/paste is working more consistently for basic Sage
types.
Note that a real number is not a good concept in computer science
sage: CDF(1)
1.0
sage: RealField(5)(1)
1.0
sage: RealField(6)(1)
1.0
and we also have other rings to treat like AA, QQbar, number fields,
polynomials...
sage: QuadraticField(2).gen()
a
sage: QuadraticField(-1).gen()
a
sage: ZZ['x']('x')
x
sage: ZZ['x','y']('x')
x
sage: QQ['x']('x')
x
sage: SR('x')
x
So +1 for this idea but it should be carefully designed.
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).
On the other hand we have some compatibility between ring of integer and
fraction field such as
sage: (3/40).factor()
2^-3 * 3 * 5^-1
sage: (4/3).gcd(2/9)
2/9
sage: (4/3).lcm(2/9)
4/3
Vincent
--
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.