Ask Your Question

How th work with enumerable and infinite set

asked 2014-07-18 15:51:01 +0200

anonymous user


updated 2023-01-09 23:59:34 +0200

tmonteil gravatar image


I am trying to do following: construct the set B that is the difference between QQ and the set of the prime numbers (note that B is a countable set). Within Sage, I tried the following

X = Set(QQ)
Y = Set(Primes())
B = Set(X.difference(Y))

then I press evaluate. I am expecting that the cardinality of B is +Infinity. But Sage does not bring any result.

I tried this also initializing B like

B = InfiniteEnumeratedSets(RR).

Could anybody please give me a hint what I am doing wrong?

Thank you very much and regards.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-18 16:25:06 +0200

Luca gravatar image

You just found a bug in Sage. Sage does not have enough knowledge to know that the set of rationals that are not prime numbers is infinite. If there was no bug, you'd have an error saying something like "Sage cannot compute the cardinality of B".

However, if you type B.cardinality??, you'll notice that what the function does is simply return len(list(self)), i.e. it constructs the list of ALL rationals that are not prime numbers, and returns its length. You get no answer because it's entered an infinite loop.

edit flag offensive delete link more


Luca gravatar imageLuca ( 2014-07-18 16:37:45 +0200 )edit

Thank you for the reply. vbk

Vasile gravatar imageVasile ( 2014-07-21 08:42:06 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-07-18 15:51:01 +0200

Seen: 336 times

Last updated: Jul 19 '14