ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 04 Jan 2013 03:19:09 -0600Express domain membershiphttps://ask.sagemath.org/question/9620/express-domain-membership/Hello
I am trying to write an expressing showing its membership in ZZ, RR, QQ.
e.g
In sage "assume(x in ZZ) "gives me error.
If I want to show that the symbol x belongs to ZZ then how should I express it ?
Best wishes
Wed, 02 Jan 2013 00:25:18 -0600https://ask.sagemath.org/question/9620/express-domain-membership/Answer by Bétréma for <p>Hello
I am trying to write an expressing showing its membership in ZZ, RR, QQ.
e.g
In sage "assume(x in ZZ) "gives me error. </p>
<p>If I want to show that the symbol x belongs to ZZ then how should I express it ?</p>
<p>Best wishes</p>
https://ask.sagemath.org/question/9620/express-domain-membership/?answer=14418#post-id-14418I don't know if you actually need *symbolic* expressions, otherwise tests are very straightforward:
sage: x=12
sage: x in ZZ, x in QQ, x in RR
(True, True, True)
Note that tests using pure Python <tt>isinstance</tt> give different output, no surprise:
sage: isinstance(x, Integer), isinstance(x, ZZ)
(True, False)
Wed, 02 Jan 2013 23:22:00 -0600https://ask.sagemath.org/question/9620/express-domain-membership/?answer=14418#post-id-14418Comment by sage_learner for <p>I don't know if you actually need <em>symbolic</em> expressions, otherwise tests are very straightforward:</p>
<pre><code>sage: x=12
sage: x in ZZ, x in QQ, x in RR
(True, True, True)
</code></pre>
<p>Note that tests using pure Python <tt>isinstance</tt> give different output, no surprise:</p>
<pre><code>sage: isinstance(x, Integer), isinstance(x, ZZ)
(True, False)
</code></pre>
https://ask.sagemath.org/question/9620/express-domain-membership/?comment=18444#post-id-18444Thank you very much.Fri, 04 Jan 2013 01:24:13 -0600https://ask.sagemath.org/question/9620/express-domain-membership/?comment=18444#post-id-18444Answer by burcin for <p>Hello
I am trying to write an expressing showing its membership in ZZ, RR, QQ.
e.g
In sage "assume(x in ZZ) "gives me error. </p>
<p>If I want to show that the symbol x belongs to ZZ then how should I express it ?</p>
<p>Best wishes</p>
https://ask.sagemath.org/question/9620/express-domain-membership/?answer=14413#post-id-14413`assume()` is a wrapper for the function with the same name in Maxima. You can find out about the syntax with the usual method of adding a `?` after the function name:
sage: assume?
In this case, to indicate that the variable `x` is in `ZZ`, you need to type:
sage: assume(x, 'integer')
Unfortunately, Sage relies on two different backends for symbolic computations, [Maxima](http://maxima.sourceforge.net) and [Pynac](http://pynac.org). Each of these uses a different method to indicate domains. We haven't reconciled these through the same interface yet. In order to indicate that a variable is real to Pynac, you can do:
sage: var('x', domain=RR)
At this moment, Pynac does not have different domains for `ZZ` or `QQ`. It only knows about `RR`, `CC` and `NN`.Wed, 02 Jan 2013 01:55:52 -0600https://ask.sagemath.org/question/9620/express-domain-membership/?answer=14413#post-id-14413Comment by sage_learner for <p><code>assume()</code> is a wrapper for the function with the same name in Maxima. You can find out about the syntax with the usual method of adding a <code>?</code> after the function name:</p>
<pre><code>sage: assume?
</code></pre>
<p>In this case, to indicate that the variable <code>x</code> is in <code>ZZ</code>, you need to type:</p>
<pre><code>sage: assume(x, 'integer')
</code></pre>
<p>Unfortunately, Sage relies on two different backends for symbolic computations, <a href="http://maxima.sourceforge.net">Maxima</a> and <a href="http://pynac.org">Pynac</a>. Each of these uses a different method to indicate domains. We haven't reconciled these through the same interface yet. In order to indicate that a variable is real to Pynac, you can do:</p>
<pre><code>sage: var('x', domain=RR)
</code></pre>
<p>At this moment, Pynac does not have different domains for <code>ZZ</code> or <code>QQ</code>. It only knows about <code>RR</code>, <code>CC</code> and <code>NN</code>.</p>
https://ask.sagemath.org/question/9620/express-domain-membership/?comment=18443#post-id-18443Thank you, answer is very useful to me. Fri, 04 Jan 2013 01:24:44 -0600https://ask.sagemath.org/question/9620/express-domain-membership/?comment=18443#post-id-18443Comment by burcin for <p><code>assume()</code> is a wrapper for the function with the same name in Maxima. You can find out about the syntax with the usual method of adding a <code>?</code> after the function name:</p>
<pre><code>sage: assume?
</code></pre>
<p>In this case, to indicate that the variable <code>x</code> is in <code>ZZ</code>, you need to type:</p>
<pre><code>sage: assume(x, 'integer')
</code></pre>
<p>Unfortunately, Sage relies on two different backends for symbolic computations, <a href="http://maxima.sourceforge.net">Maxima</a> and <a href="http://pynac.org">Pynac</a>. Each of these uses a different method to indicate domains. We haven't reconciled these through the same interface yet. In order to indicate that a variable is real to Pynac, you can do:</p>
<pre><code>sage: var('x', domain=RR)
</code></pre>
<p>At this moment, Pynac does not have different domains for <code>ZZ</code> or <code>QQ</code>. It only knows about <code>RR</code>, <code>CC</code> and <code>NN</code>.</p>
https://ask.sagemath.org/question/9620/express-domain-membership/?comment=18440#post-id-18440Then you can mark my answer as the accepted one. This will prevent this question from getting in the way if someone searches for the list of unanswered questions on this site.Fri, 04 Jan 2013 03:19:09 -0600https://ask.sagemath.org/question/9620/express-domain-membership/?comment=18440#post-id-18440