Ask Your Question

Revision history [back]

This is because range spits out Python integers, and not Sage integers.

Python integers are "machine integers", that are designed to be fast, but can only be used for standard operations, and don't know about the rich structure of the ring of integers.

You could use srange, which works like range but gives you Sage integers.

If you use range, then use ZZ(number).is_prime() to first convert the numbers to integers before applying the .is_prime() method.

What is_prime(number) does is to try and apply the .is_range() method if it is available, and otherwise first convert the number to a Sage integer, then apply the .is_range() method.

This is because range spits out Python integers, and not Sage integers.

Python integers are "machine integers", that are designed to be fast, but can only be used for standard operations, and don't know about the rich structure of the ring of integers.

You could use srange, which works like range but gives you Sage integers.

If you use range, then use ZZ(number).is_prime() to first convert the numbers to integers before applying the .is_prime() method.

What is_prime(number) does is to try and apply the .is_range().is_prime() method if it is available, and otherwise first convert the number to a Sage integer, then apply the .is_range().is_prime() method.