ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 21 Jul 2014 08:42:06 +0200How th work with enumerable and infinite sethttps://ask.sagemath.org/question/23467/how-th-work-with-enumerable-and-infinite-set/ Hello,
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))
B.cardinality()
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.
vbk
Fri, 18 Jul 2014 15:51:01 +0200https://ask.sagemath.org/question/23467/how-th-work-with-enumerable-and-infinite-set/Answer by Luca for <p>Hello,</p>
<p>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</p>
<pre><code>X = Set(QQ)
Y = Set(Primes())
B = Set(X.difference(Y))
B.cardinality()
</code></pre>
<p>then I press evaluate. I am expecting that the cardinality of B is +Infinity. But Sage does not bring any result.</p>
<p>I tried this also initializing B like</p>
<pre><code>B = InfiniteEnumeratedSets(RR).
</code></pre>
<p>Could anybody please give me a hint what I am doing wrong?</p>
<p>Thank you very much and regards.</p>
<p>vbk</p>
https://ask.sagemath.org/question/23467/how-th-work-with-enumerable-and-infinite-set/?answer=23468#post-id-23468You 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.
Fri, 18 Jul 2014 16:25:06 +0200https://ask.sagemath.org/question/23467/how-th-work-with-enumerable-and-infinite-set/?answer=23468#post-id-23468Comment by Luca for <p>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".</p>
<p>However, if you type <code>B.cardinality??</code>, you'll notice that what the function does is simply <code>return len(list(self))</code>, 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.</p>
https://ask.sagemath.org/question/23467/how-th-work-with-enumerable-and-infinite-set/?comment=23469#post-id-23469This is now http://trac.sagemath.org/ticket/16676Fri, 18 Jul 2014 16:37:45 +0200https://ask.sagemath.org/question/23467/how-th-work-with-enumerable-and-infinite-set/?comment=23469#post-id-23469Comment by Vasile for <p>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".</p>
<p>However, if you type <code>B.cardinality??</code>, you'll notice that what the function does is simply <code>return len(list(self))</code>, 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.</p>
https://ask.sagemath.org/question/23467/how-th-work-with-enumerable-and-infinite-set/?comment=23508#post-id-23508Thank you for the reply.
vbkMon, 21 Jul 2014 08:42:06 +0200https://ask.sagemath.org/question/23467/how-th-work-with-enumerable-and-infinite-set/?comment=23508#post-id-23508