Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/rings/ideal_monoid.py
4079 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
TESTS::
45
46
sage: R = QuadraticField(-23, 'a')
47
sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M # indirect doctest
48
Monoid of ideals of Number Field in a with defining polynomial x^2 + 23
49
"""
50
self.__R = R
51
Parent.__init__(self, base = sage.rings.integer_ring.ZZ, category = Monoids())
52
self._populate_coercion_lists_()
53
54
def _repr_(self):
55
r"""
56
TESTS::
57
58
sage: R = QuadraticField(-23, 'a')
59
sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M._repr_()
60
'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23'
61
"""
62
return "Monoid of ideals of %s"%self.__R
63
64
def ring(self):
65
r"""
66
Return the ring of which this is the ideal monoid.
67
68
EXAMPLE::
69
70
sage: R = QuadraticField(-23, 'a')
71
sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M.ring() is R
72
True
73
"""
74
return self.__R
75
76
def _element_constructor_(self, x):
77
r"""
78
Create an ideal in this monoid from ``x``.
79
80
EXAMPLES::
81
82
sage: R.<a> = QuadraticField(-23)
83
sage: M = sage.rings.ideal_monoid.IdealMonoid(R)
84
sage: M(a) # indirect doctest
85
Fractional ideal (a)
86
sage: M([a-4, 13])
87
Fractional ideal (13, 1/2*a + 9/2)
88
"""
89
try:
90
side = x.side()
91
except (AttributeError,TypeError):
92
side = None
93
try:
94
x = x.gens()
95
except AttributeError:
96
pass
97
if side is None:
98
y = self.__R.ideal(x)
99
else:
100
y = self.__R.ideal(x,side=side)
101
y._set_parent(self)
102
return y
103
104
def _coerce_map_from_(self, x):
105
r"""
106
Used by coercion framework.
107
108
EXAMPLE::
109
110
sage: R = QuadraticField(-23, 'a')
111
sage: M = R.ideal_monoid()
112
sage: M.has_coerce_map_from(R)
113
True
114
sage: M.has_coerce_map_from(QQ.ideal_monoid())
115
True
116
sage: M.has_coerce_map_from(Zmod(6))
117
False
118
sage: M.has_coerce_map_from(loads(dumps(M)))
119
True
120
"""
121
122
if isinstance(x, IdealMonoid_c):
123
return self.ring().has_coerce_map_from(x.ring())
124
else:
125
return self.ring().has_coerce_map_from(x)
126
127
def __cmp__(self, other):
128
r"""
129
Comparison function.
130
131
EXAMPLE::
132
133
sage: R = QuadraticField(-23, 'a')
134
sage: M = R.ideal_monoid()
135
sage: M == QQ
136
False
137
sage: M == 17
138
False
139
sage: M == R.ideal_monoid()
140
True
141
"""
142
if not isinstance(other, IdealMonoid_c):
143
return cmp(type(self), type(other))
144
else:
145
return cmp(self.ring(), other.ring())
146
147