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.

Reply via email to