Ask Your Question

How th work with enumerable and infinite set

asked 2014-07-18 08:51:01 -0500

anonymous user


updated 2014-07-19 04:21:12 -0500


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 09:25:06 -0500

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 09:37:45 -0500 )edit

Thank you for the reply. vbk

Vasile gravatar imageVasile ( 2014-07-21 01:42:06 -0500 )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 08:51:01 -0500

Seen: 97 times

Last updated: Jul 19 '14