ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 25 Mar 2015 09:33:02 -0500How to define / create a new Ringhttp://ask.sagemath.org/question/26299/how-to-define-create-a-new-ring/Hi!
I just installed the version 6.5 of Sage. Then I saw in the help some page/tutorial about Basic Rings but I could not find an article (I googled) or an answer for the following:
How can I create a new ring? For example: How can I create a kind of ring of Integers (called ZZ in Sage) where I have only , say, even numbers?
Examples:
sage: sqrt(4) in myZZ
True
sage: 3 in myZZ
False
Thank you for any help!Tue, 24 Mar 2015 02:58:46 -0500http://ask.sagemath.org/question/26299/how-to-define-create-a-new-ring/Answer by tmonteil for <p>Hi!</p>
<p>I just installed the version 6.5 of Sage. Then I saw in the help some page/tutorial about Basic Rings but I could not find an article (I googled) or an answer for the following:</p>
<p>How can I create a new ring? For example: How can I create a kind of ring of Integers (called ZZ in Sage) where I have only , say, even numbers? </p>
<p>Examples: </p>
<p>sage: sqrt(4) in myZZ
True</p>
<p>sage: 3 in myZZ
False</p>
<p>Thank you for any help!</p>
http://ask.sagemath.org/question/26299/how-to-define-create-a-new-ring/?answer=26303#post-id-26303You can have a look at [this thematic tutorial](http://www.sagemath.org/doc/thematic_tutorials/coercion_and_categories.html) that explains how to implement new algebraic structures in Sage.
To implement the `in` feature, you have to implement a `__contains__` method.
Do not hesitate to post your preliminary code for more questions.
Tue, 24 Mar 2015 07:27:29 -0500http://ask.sagemath.org/question/26299/how-to-define-create-a-new-ring/?answer=26303#post-id-26303Comment by LRM for <p>You can have a look at <a href="http://www.sagemath.org/doc/thematic_tutorials/coercion_and_categories.html">this thematic tutorial</a> that explains how to implement new algebraic structures in Sage.</p>
<p>To implement the <code>in</code> feature, you have to implement a <code>__contains__</code> method.</p>
<p>Do not hesitate to post your preliminary code for more questions.</p>
http://ask.sagemath.org/question/26299/how-to-define-create-a-new-ring/?comment=26328#post-id-26328I will take a look now. Thank you for your attention.Wed, 25 Mar 2015 09:33:02 -0500http://ask.sagemath.org/question/26299/how-to-define-create-a-new-ring/?comment=26328#post-id-26328