Ask Your Question
1

Express domain membership

asked 2013-01-02 07:25:18 +0200

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
2

answered 2013-01-02 08:55:52 +0200

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

Comments

Thank you, answer is very useful to me.

sage_learner gravatar imagesage_learner ( 2013-01-04 08:24:44 +0200 )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 10:19:09 +0200 )edit
0

answered 2013-01-03 06:22:00 +0200

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

Comments

Thank you very much.

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

Stats

Asked: 2013-01-02 07:25:18 +0200

Seen: 1,099 times

Last updated: Jan 03 '13