Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/rings/ideal_monoid.py
8817 views
1
"""
2
Monoid of ideals in a commutative ring
3
"""
4
5
from commutative_ring import is_CommutativeRing
6
#from sage.structure.parent_base import ParentWithBase
7
from sage.structure.parent import Parent
8
import sage.rings.integer_ring
9
import ideal
10
from sage.categories.monoids import Monoids
11
12
def IdealMonoid(R):
13
r"""
14
Return the monoid of ideals in the ring ``R``.
15
16
EXAMPLE::
17
18
sage: R = QQ['x']
19
sage: sage.rings.ideal_monoid.IdealMonoid(R)
20
Monoid of ideals of Univariate Polynomial Ring in x over Rational Field
21
"""
22
return IdealMonoid_c(R)
23
24
class IdealMonoid_c(Parent):
25
r"""
26
The monoid of ideals in a commutative ring.
27
28
TESTS::
29
30
sage: R = QQ['x']
31
sage: M = sage.rings.ideal_monoid.IdealMonoid(R)
32
sage: TestSuite(M).run()
33
Failure in _test_category:
34
...
35
The following tests failed: _test_elements
36
37
(The "_test_category" test fails but I haven't the foggiest idea why.)
38
"""
39
40
Element = ideal.Ideal_generic # this doesn't seem to do anything
41
42
def __init__(self, R):
43
r"""
44
Initialize ``self``.
45
46
TESTS::
47
48
sage: R = QuadraticField(-23, 'a')
49
sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M # indirect doctest
50
Monoid of ideals of Number Field in a with defining polynomial x^2 + 23
51
"""
52
self.__R = R
53
Parent.__init__(self, base = sage.rings.integer_ring.ZZ, category = Monoids())
54
self._populate_coercion_lists_()
55
56
def _repr_(self):
57
r"""
58
Return a string representation of ``self``.
59
60
TESTS::
61
62
sage: R = QuadraticField(-23, 'a')
63
sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M._repr_()
64
'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23'
65
"""
66
return "Monoid of ideals of %s"%self.__R
67
68
def ring(self):
69
r"""
70
Return the ring of which this is the ideal monoid.
71
72
EXAMPLE::
73
74
sage: R = QuadraticField(-23, 'a')
75
sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M.ring() is R
76
True
77
"""
78
return self.__R
79
80
def _element_constructor_(self, x):
81
r"""
82
Create an ideal in this monoid from ``x``.
83
84
EXAMPLES::
85
86
sage: R.<a> = QuadraticField(-23)
87
sage: M = sage.rings.ideal_monoid.IdealMonoid(R)
88
sage: M(a) # indirect doctest
89
Fractional ideal (a)
90
sage: M([a-4, 13])
91
Fractional ideal (13, 1/2*a + 9/2)
92
"""
93
try:
94
side = x.side()
95
except (AttributeError,TypeError):
96
side = None
97
try:
98
x = x.gens()
99
except AttributeError:
100
pass
101
if side is None:
102
y = self.__R.ideal(x)
103
else:
104
y = self.__R.ideal(x,side=side)
105
y._set_parent(self)
106
return y
107
108
def _coerce_map_from_(self, x):
109
r"""
110
Used by coercion framework.
111
112
EXAMPLE::
113
114
sage: R = QuadraticField(-23, 'a')
115
sage: M = R.ideal_monoid()
116
sage: M.has_coerce_map_from(R) # indirect doctest
117
True
118
sage: M.has_coerce_map_from(QQ.ideal_monoid())
119
True
120
sage: M.has_coerce_map_from(Zmod(6))
121
False
122
sage: M.has_coerce_map_from(loads(dumps(M)))
123
True
124
"""
125
if isinstance(x, IdealMonoid_c):
126
return self.ring().has_coerce_map_from(x.ring())
127
else:
128
return self.ring().has_coerce_map_from(x)
129
130
def __cmp__(self, other):
131
r"""
132
Comparison function.
133
134
EXAMPLE::
135
136
sage: R = QuadraticField(-23, 'a')
137
sage: M = R.ideal_monoid()
138
sage: M == QQ
139
False
140
sage: M == 17
141
False
142
sage: M == R.ideal_monoid()
143
True
144
"""
145
if not isinstance(other, IdealMonoid_c):
146
return cmp(type(self), type(other))
147
else:
148
return cmp(self.ring(), other.ring())
149
150