Re: [sage-support] something seems wrong here

2022-01-02 Thread slelievre
2022-01-02 00:00:56 UTC, Michael Beeson on sage-devel:

> sage: d = 6
> sage: p = d/2
> sage: p
> 3
> sage: is_prime(p)
> False  #  Huh?!!  
> sage: is_prime(3)
> True
> sage: p==3
> True
>
> This happens in version 8.7  and also in the current version (installed 
yesterday)

William Stein answered:

> The parent of p is QQ (the rational field).
> p is not a prime number of the **rational field**.
> You should coerce p to ZZ first.

To change `p` to an integer before testing whether it is prime:

```
sage: d = 6
sage: parent(d)
Integer Ring

sage: p = d/2
sage: parent(p)
Rational Field

sage: p = ZZ(p)
sage: is_prime(p)
True
```

Or, to take quotients in the integers from the start, use

```
sage: d = 6
sage: p = d // 2
sage: parent(p)
Integer Ring
sage: is_prime(p)
True
```

The behaviour of `is_prime` for field elements is the object of

- Sage Trac ticket #17919
  Disallow is_prime() for FieldElement
  https://trac.sagemath.org/ticket/17919

- Sage Trac ticket #32321
  Make is_prime() return true for rational numbers that are prime as 
integers
  https://trac.sagemath.org/ticket/32321

See also:

- Sage Trac ticket #32340
  Document behavior of .is_prime() for number fields
  https://trac.sagemath.org/ticket/32340

- Sage Trac tickets whose summary contains is_prime
  https://trac.sagemath.org/query?order=id&desc=1&summary=~is_prime

-- 
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/74b4969e-5fd1-4612-9b2b-6a89d95cd1c2n%40googlegroups.com.


Re: [sage-support] something seems wrong here

2022-01-01 Thread William Stein
More here:  
https://doc.sagemath.org/html/en/reference/structure/sage/structure/element.html#sage.structure.element.RingElement.is_prime

On Sat, Jan 1, 2022 at 4:27 PM William Stein  wrote:
>
> On Sat, Jan 1, 2022 at 4:01 PM Michael Beeson  wrote:
> >
> > sage: d = 6
> >
> > sage: p = d/2
> >
> > sage: p
> >
> > 3
> >
> > sage: is_prime(p)
> >
> > False  #  Huh?!!
>
> The parent of p is QQ (the rational field).
> p is not a prime number of the **rational field**.
> You should coerce p to ZZ first.
>
> In retrospect, we probably should have just made is_prime throw an
> exception if the parent ring is a field, since the ring theory
> definition of prime number isn't very useful in a field.
>
> >
> > sage: is_prime(3)
> >
> > True
> >
> > sage: p==3
> >
> > True
> >
> > This happens in version 8.7  and also in the current version (installed 
> > yesterday)
> >
> >
> > --
> > 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/9cb13872-298c-4463-b27d-b77ea288bfedn%40googlegroups.com.
>
>
>
> --
> William (http://wstein.org)



-- 
William (http://wstein.org)

-- 
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/CACLE5GDVrKCa8-SCn-2p22oXDyQgtnS6s26upXCA-z%2Bx9EZAuw%40mail.gmail.com.


Re: [sage-support] something seems wrong here

2022-01-01 Thread William Stein
On Sat, Jan 1, 2022 at 4:01 PM Michael Beeson  wrote:
>
> sage: d = 6
>
> sage: p = d/2
>
> sage: p
>
> 3
>
> sage: is_prime(p)
>
> False  #  Huh?!!

The parent of p is QQ (the rational field).
p is not a prime number of the **rational field**.
You should coerce p to ZZ first.

In retrospect, we probably should have just made is_prime throw an
exception if the parent ring is a field, since the ring theory
definition of prime number isn't very useful in a field.

>
> sage: is_prime(3)
>
> True
>
> sage: p==3
>
> True
>
> This happens in version 8.7  and also in the current version (installed 
> yesterday)
>
>
> --
> 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/9cb13872-298c-4463-b27d-b77ea288bfedn%40googlegroups.com.



-- 
William (http://wstein.org)

-- 
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/CACLE5GDnGOFcb2OEO3OCczOuj-Yvzxa-k%3Dvx0xfoYog52Mogow%40mail.gmail.com.