sage: (2^23+1)/3
2796203
sage: _.is_prime()
False
sage: factor(2796203)
2796203
sage: for n in range(1,100):
....: if is_prime((2^n - (-1)^n)/3):
....: print((2^n - (-1)^n)/3)
....:
sage:
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.
...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".
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+...@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.
Hello,I thought I'd try Sage for a casual computation. I was interested in which numbers of the form (2^n - (-1)^n)/3 are prime. I first tried out n=23:
sage: (2^23+1)/3
2796203
sage: _.is_prime()
False
sage: factor(2796203)
2796203
intrinsic Factorisation(n::FldRatElt) -> SeqEnum
L,u:=Factorisation(Numerator(n));
L:= L cat [ <u[1],-u[2]> : u in Factorisation(Denominator(n))];
return L,u;
end intrinsic;
intrinsic Factorisation(n::FldFunRatMElt) -> SeqEnum
L,u:=Factorisation(Numerator(n));
L:= L cat [ <u[1],-u[2]> : u in Factorisation(Denominator(n))];
return L,u;
end intrinsic;
intrinsic Factorisation(n::FldFunRatUElt) -> SeqEnum
L,u:=Factorisation(Numerator(n));
L:= L cat [ <u[1],-u[2]> : u in Factorisation(Denominator(n))];
return L,u;
end intrinsic;
intrinsic Factor(a::.)->SeqEnum
return Factorisation(a);
end intrinsic;
sage: is_prime(12/4)
False
Just curious -- does that have the *potential* to break Magma library
code? E.g., maybe deep in some package code I wrote 20 years ago
for Magma, I use Factorization on a reational, and assume that the
output is "trivial". (I'm pretty sure I didn't, but...)
--
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+unsubscribe@googlegroups.com.
See https://trac.sagemath.org/ticket/21067
for a rational factor_list().
sage: factor(12/21)
2^2 * 7^-1
try:
return n.is_prime()
except (AttributeError, NotImplementedError):
return ZZ(n).is_prime()
Why not introducing a different function, is_prime_integer() say, keeping is_prime() as it is now?
Of course, x.is_prime_integer(), or is_prime_integer(x), would return ZZ(x).is_prime().
Then, for the casual user, we should advertise (in examples, tutorials, etc.) the use of is_prime_integer() over is_prime().
Note that the casual user may discover is_prime_integer() by the standard TAB mechanism, since its name starts by "is_prime". Facing the choice between the two functions, he would probably (hopefully?) opt for is_prime_integer(), which is self-explanatory.
But will MATLAB tell you that two equal matrices have different ranks? I
know sage will do it.
Why not assume by default that when someone enters a floating point number, they intend it as a member of QQ, at least in this case.
Hello,I thought I'd try Sage for a casual computation. I was interested in which numbers of the form (2^n - (-1)^n)/3 are prime. I first tried out n=23:
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.
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? This goes beyond "serious lack of reviewers" and "dev shortage".There was always the notion that you shouldn't "team up" for ticket review. I'm now breaking it. If YOU are interested in fixing the above or similar problems please mail me. There are also about 25 calculus tickets from me waiting for review. But probably noone is really interested in that either. The algebraists can have their Sage back. Good job.
On 28/03/18 10:33, Ralf Stephan wrote:
Ask yourself, are these arguments you give for current is_prime(x) behaviour not just the inertia of your thinking.
Wolfram tells me plainly "1/3 (2^23 + 1) is a prime number"---no ambiguity, no attempt to show a glimpse of algebraic truth.
Pari gives
? isprime((2^23+1)/3)
%1 = 1
Giac:
>> is_prime((2^23+1)/3)
1
SymPy however:
In [7]: isprime((2**23+1)/3)
Out[7]: False
But then it's clear that the value is not integer:
In [8]: (2**23+1)/3
Out[8]: 2796203.0
Why not improve mathematics? Why not define the primality term you apply in the element is_prime() as having a different name than "prime"? Why not introduce 123/1 as notation to avoid ambiguities in mathematics? I'm quite astonished that mathematicians allow these fuzziness in their language, it is unusual.
The documentation of RingElement.is_prime [1], which most people will never read, does give the example of fields, where an element is never prime.
I am not sure what will be the impact of changing the global is_prime function (I used it for rings other than ZZ), but updating its documentation [2] not to say "Return True if n is a prime *number*", and saying something about rings which are not the integers, is surely better than the current situation.
Regarding SymPy, I think this is something more general to Python. Even unrelated to mathematics, if one wants for example to iterate over the first half of some list, they might use range(n/2) where n is an integer which raises:
TypeError: range() integer end argument expected, got float.
In such scenarios, the programmer will soon learn about floor division. The difference with is_prime is that a non-integer is expected...
Regards,
TB
[1] https://doc.sagemath.org/html/en/reference/structure/sage/structure/element.html#sage.structure.element.RingElement.is_prime
[2] https://doc.sagemath.org/html/en/reference/rings_standard/sage/arith/misc.html#sage.arith.misc.is_prime
Hi Ralf,
On 2018-03-28, Ralf Stephan <gtr...@gmail.com> wrote:
> Ask yourself, are these arguments you give for current is_prime(x)
> behaviour not just the inertia of your thinking.
No. It is a sign of appreciation of mathematical notions. Sorry to start
with politics here, but I am against populism. And dropping mathematical
rigor in order to get more votes (i.e., more users), just because of some
guess that a large proportion of potential users of maths software might
refuse to start learning about mathematical notions, *is* populism, IMHO.
Also, that attitude is a grave indectment against once own educational
capacity.
Instead, I would strive to improve mathematical knowledge of the users.
Not by letting the user fall into the pitfalls of maths, but by pointing
the users to such pitfalls (warning messages etc.).
> Wolfram tells me plainly "1/3 (2^23 + 1) is a prime number"---no ambiguity,
> no attempt to show a glimpse of algebraic truth.
--
Marc
--
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+...@googlegroups.com.
I thought I'd try Sage for a casual computation. I was interested in which numbers of the form (2^n - (-1)^n)/3 are prime. I first tried out n=23:
sage: (2^23+1)/3
2796203
sage: _.is_prime()
False
sage: factor(2796203)
2796203It turns out that Rational.is_prime does not exist and the fallback gives false answers.
There was always the notion that you shouldn't "team up" for ticket review. I'm now breaking it.
If YOU are interested in fixing the above or similar problems please mail me. There are also about 25 calculus tickets from me waiting for review. But probably noone is really interested in that either. The algebraists can have their Sage back. Good job.
It's surprisingly easy to implement this, due to how Robert Bradshaw
rewrote this part of the Sage preparser. If you define this
function in a notebook or command line sage session:
def RealNumber(s):
if '.' not in s:
return QQ(s)
a = s.split('.')
return ZZ(a[0]) + ZZ(a[1])/10^len(a[1])
then all real number literals will be interpreted as exact rationals!
Thanks -- I should have added that the above was a quick "proof of concept".
Hello,
I thought I'd try Sage for a casual computation. I was interested in which numbers of the form (2^n - (-1)^n)/3 are prime. I first tried out n=23:
sage: (2^23+1)/3
2796203
sage: _.is_prime()
False
sage: factor(2796203)
2796203It turns out that Rational.is_prime does not exist and the fallback gives false answers.
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? This goes beyond "serious lack of reviewers" and "dev shortage".There was always the notion that you shouldn't "team up" for ticket review. I'm now breaking it. If YOU are interested in fixing the above or similar problems please mail me. There are also about 25 calculus tickets from me waiting for review. But probably noone is really interested in that either. The algebraists can have their Sage back. Good job.
+1
--
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+unsubscribe@googlegroups.com.
I don't think this will satisfy Ralf's casual user who will see 100 warnings output from their loop and not find any of the primes they were hoping for.
sage: is_prime(I)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
............
TypeError: Unable to coerce I to an integer
Have we come to any conclusions on what steps should be taken after this topic? What seems to be the concensus? Or, at the very least, could someone give a listing of the options we have so that we can give it a poll or something similar?
--
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+...@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.