Ask Your Question

Express domain membership

asked 2013-01-02 00:25:18 -0500

sage_learner gravatar image

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

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2013-01-02 01:55:52 -0500

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 and Pynac. 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.

edit flag offensive delete link more


Thank you, answer is very useful to me.

sage_learner gravatar imagesage_learner ( 2013-01-04 01:24:44 -0500 )edit

Then 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.

burcin gravatar imageburcin ( 2013-01-04 03:19:09 -0500 )edit

answered 2013-01-02 23:22:00 -0500

I 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 isinstance give different output, no surprise:

sage: isinstance(x, Integer), isinstance(x, ZZ)
(True, False)
edit flag offensive delete link more


Thank you very much.

sage_learner gravatar imagesage_learner ( 2013-01-04 01:24:13 -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


Asked: 2013-01-02 00:25:18 -0500

Seen: 482 times

Last updated: Jan 02 '13