Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/rings/ideal.py
8817 views
1
r"""
2
Ideals of commutative rings.
3
4
Sage provides functionality for computing with ideals. One can create
5
an ideal in any commutative or non-commutative ring `R` by giving a
6
list of generators, using the notation ``R.ideal([a,b,...])``. The case
7
of non-commutative rings is implemented in
8
:mod:`~sage.rings.noncommutative_ideals`.
9
10
A more convenient notation may be ``R*[a,b,...]`` or ``[a,b,...]*R``.
11
If `R` is non-commutative, the former creates a left and the latter
12
a right ideal, and ``R*[a,b,...]*R`` creates a two-sided ideal.
13
"""
14
15
#*****************************************************************************
16
# Copyright (C) 2005 William Stein <[email protected]>
17
#
18
# Distributed under the terms of the GNU General Public License (GPL)
19
#
20
# This code is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
# General Public License for more details.
24
#
25
# The full text of the GPL is available at:
26
#
27
# http://www.gnu.org/licenses/
28
#*****************************************************************************
29
30
from types import GeneratorType
31
32
import sage.misc.latex as latex
33
import sage.rings.ring
34
import commutative_ring
35
from sage.structure.element import MonoidElement
36
from sage.interfaces.singular import singular as singular_default
37
import sage.rings.infinity
38
from sage.structure.sequence import Sequence
39
40
def Ideal(*args, **kwds):
41
r"""
42
Create the ideal in ring with given generators.
43
44
There are some shorthand notations for creating an ideal, in
45
addition to using the :func:`Ideal` function:
46
47
- ``R.ideal(gens, coerce=True)``
48
- ``gens*R``
49
- ``R*gens``
50
51
INPUT:
52
53
- ``R`` - A ring (optional; if not given, will try to infer it from
54
``gens``)
55
56
- ``gens`` - list of elements generating the ideal
57
58
- ``coerce`` - bool (optional, default: ``True``);
59
whether ``gens`` need to be coerced into the ring.
60
61
62
OUTPUT: The ideal of ring generated by ``gens``.
63
64
EXAMPLES::
65
66
sage: R, x = PolynomialRing(ZZ, 'x').objgen()
67
sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2])
68
sage: I
69
Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring
70
sage: Ideal(R, [4 + 3*x + x^2, 1 + x^2])
71
Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring
72
sage: Ideal((4 + 3*x + x^2, 1 + x^2))
73
Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring
74
75
::
76
77
sage: ideal(x^2-2*x+1, x^2-1)
78
Ideal (x^2 - 2*x + 1, x^2 - 1) of Univariate Polynomial Ring in x over Integer Ring
79
sage: ideal([x^2-2*x+1, x^2-1])
80
Ideal (x^2 - 2*x + 1, x^2 - 1) of Univariate Polynomial Ring in x over Integer Ring
81
sage: l = [x^2-2*x+1, x^2-1]
82
sage: ideal(f^2 for f in l)
83
Ideal (x^4 - 4*x^3 + 6*x^2 - 4*x + 1, x^4 - 2*x^2 + 1) of
84
Univariate Polynomial Ring in x over Integer Ring
85
86
This example illustrates how Sage finds a common ambient ring for
87
the ideal, even though 1 is in the integers (in this case).
88
89
::
90
91
sage: R.<t> = ZZ['t']
92
sage: i = ideal(1,t,t^2)
93
sage: i
94
Ideal (1, t, t^2) of Univariate Polynomial Ring in t over Integer Ring
95
sage: ideal(1/2,t,t^2)
96
Principal ideal (1) of Univariate Polynomial Ring in t over Rational Field
97
98
This shows that the issues at :trac:`1104` are resolved::
99
100
sage: Ideal(3, 5)
101
Principal ideal (1) of Integer Ring
102
sage: Ideal(ZZ, 3, 5)
103
Principal ideal (1) of Integer Ring
104
sage: Ideal(2, 4, 6)
105
Principal ideal (2) of Integer Ring
106
107
You have to provide enough information that Sage can figure out
108
which ring to put the ideal in.
109
110
::
111
112
sage: I = Ideal([])
113
Traceback (most recent call last):
114
...
115
ValueError: unable to determine which ring to embed the ideal in
116
117
sage: I = Ideal()
118
Traceback (most recent call last):
119
...
120
ValueError: need at least one argument
121
122
Note that some rings use different ideal implementations than the standard,
123
even if they are PIDs.::
124
125
sage: R.<x> = GF(5)[]
126
sage: I = R*(x^2+3)
127
sage: type(I)
128
<class 'sage.rings.polynomial.ideal.Ideal_1poly_field'>
129
130
You can also pass in a specific ideal type::
131
132
sage: from sage.rings.ideal import Ideal_pid
133
sage: I = Ideal(x^2+3,ideal_class=Ideal_pid)
134
sage: type(I)
135
<class 'sage.rings.ideal.Ideal_pid'>
136
137
TESTS::
138
139
sage: R, x = PolynomialRing(ZZ, 'x').objgen()
140
sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2])
141
sage: I == loads(dumps(I))
142
True
143
144
::
145
146
sage: I = Ideal(R, [4 + 3*x + x^2, 1 + x^2])
147
sage: I == loads(dumps(I))
148
True
149
150
::
151
152
sage: I = Ideal((4 + 3*x + x^2, 1 + x^2))
153
sage: I == loads(dumps(I))
154
True
155
156
This shows that the issue at :trac:`5477` is fixed::
157
158
sage: R.<x> = QQ[]
159
sage: I = R.ideal([x + x^2])
160
sage: J = R.ideal([2*x + 2*x^2])
161
sage: J
162
Principal ideal (x^2 + x) of Univariate Polynomial Ring in x over Rational Field
163
sage: S = R.quotient_ring(I)
164
sage: U = R.quotient_ring(J)
165
sage: I == J
166
True
167
sage: S == U
168
True
169
"""
170
if len(args) == 0:
171
raise ValueError, "need at least one argument"
172
if len(args) == 1 and args[0] == []:
173
raise ValueError, "unable to determine which ring to embed the ideal in"
174
175
first = args[0]
176
177
if not isinstance(first, sage.rings.ring.Ring):
178
if isinstance(first, Ideal_generic) and len(args) == 1:
179
R = first.ring()
180
gens = first.gens()
181
else:
182
if isinstance(first, (list, tuple, GeneratorType)) and len(args) == 1:
183
gens = first
184
else:
185
gens = args
186
gens = Sequence(gens)
187
R = gens.universe()
188
else:
189
R = first
190
gens = args[1:]
191
192
if not commutative_ring.is_CommutativeRing(R):
193
raise TypeError, "R must be a commutative ring"
194
195
return R.ideal(*gens, **kwds)
196
197
def is_Ideal(x):
198
r"""
199
Return ``True`` if object is an ideal of a ring.
200
201
EXAMPLES:
202
203
A simple example involving the ring of integers. Note
204
that Sage does not interpret rings objects themselves as ideals.
205
However, one can still explicitly construct these ideals::
206
207
sage: from sage.rings.ideal import is_Ideal
208
sage: R = ZZ
209
sage: is_Ideal(R)
210
False
211
sage: 1*R; is_Ideal(1*R)
212
Principal ideal (1) of Integer Ring
213
True
214
sage: 0*R; is_Ideal(0*R)
215
Principal ideal (0) of Integer Ring
216
True
217
218
Sage recognizes ideals of polynomial rings as well::
219
220
sage: R = PolynomialRing(QQ, 'x'); x = R.gen()
221
sage: I = R.ideal(x^2 + 1); I
222
Principal ideal (x^2 + 1) of Univariate Polynomial Ring in x over Rational Field
223
sage: is_Ideal(I)
224
True
225
sage: is_Ideal((x^2 + 1)*R)
226
True
227
"""
228
return isinstance(x, Ideal_generic)
229
230
231
class Ideal_generic(MonoidElement):
232
"""
233
An ideal.
234
235
See :func:`Ideal()`.
236
"""
237
def __init__(self, ring, gens, coerce=True):
238
"""
239
Initialize this ideal.
240
241
INPUT:
242
243
- ``ring`` -- A ring
244
245
- ``gens`` -- The generators for this ideal
246
247
- ``coerce`` -- (default: ``True``) If ``gens`` needs to be coerced
248
into ``ring``.
249
250
EXAMPLES::
251
252
sage: R, x = PolynomialRing(ZZ, 'x').objgen()
253
sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2])
254
sage: I
255
Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring
256
"""
257
self.__ring = ring
258
if not isinstance(gens, (list, tuple)):
259
gens = [gens]
260
if coerce:
261
gens = [ring(x) for x in gens]
262
263
gens = tuple(gens)
264
if len(gens)==0: gens=(ring.zero_element(),)
265
self.__gens = gens
266
MonoidElement.__init__(self, ring.ideal_monoid())
267
268
def _repr_short(self):
269
"""
270
Represent the list of generators.
271
272
EXAMPLE::
273
274
sage: P.<a,b,c> = QQ[]
275
sage: P*[a^2,a*b+c,c^3]
276
Ideal (a^2, a*b + c, c^3) of Multivariate Polynomial Ring in a, b, c over Rational Field
277
sage: (P*[a^2,a*b+c,c^3])._repr_short()
278
'(a^2, a*b + c, c^3)'
279
280
If the string representation of a generator contains a line break,
281
the generators are not represented from left to right but from
282
top to bottom. This is the case, e.g., for matrices::
283
284
sage: MS = MatrixSpace(QQ,2,2)
285
sage: MS*[MS.1,2]
286
Left Ideal
287
(
288
[0 1]
289
[0 0],
290
<BLANKLINE>
291
[2 0]
292
[0 2]
293
)
294
of Full MatrixSpace of 2 by 2 dense matrices over Rational Field
295
296
297
"""
298
L = []
299
has_return = False
300
for x in self.gens():
301
s = repr(x)
302
if '\n' in s:
303
has_return = True
304
s = s.replace('\n','\n ')
305
L.append(s)
306
if has_return:
307
return '\n(\n %s\n)\n'%(',\n\n '.join(L))
308
return '(%s)'%(', '.join(L))
309
310
def __repr__(self):
311
"""
312
Return a string representation of ``self``.
313
314
EXAMPLES::
315
316
sage: P.<a,b,c> = QQ[]
317
sage: P*[a^2,a*b+c,c^3] # indirect doctest
318
Ideal (a^2, a*b + c, c^3) of Multivariate Polynomial Ring in a, b, c over Rational Field
319
"""
320
return "Ideal %s of %s"%(self._repr_short(), self.ring())
321
322
def __cmp__(self, other):
323
"""
324
Compares the generators of two ideals.
325
326
INPUT:
327
328
- ``other`` -- an ideal
329
330
OUTPUT:
331
332
- 0 if ``self`` and ``other`` have the same generators, 1 otherwise.
333
334
EXAMPLE::
335
336
sage: R = ZZ; I = ZZ*2; J = ZZ*(-2)
337
sage: cmp(I,J)
338
0
339
"""
340
S = set(self.gens())
341
T = set(other.gens())
342
if S == T:
343
return 0
344
return cmp(self.gens(), other.gens())
345
346
def __contains__(self, x):
347
"""
348
Check if ``x`` is in ``self``.
349
350
EXAMPLES::
351
352
sage: P.<a,b,c> = QQ[]
353
sage: I = P*[a, b]
354
sage: a + b in I
355
True
356
sage: P2.<w,x,y,z> = QQ[]
357
sage: x + 2*y + w*z in I
358
False
359
"""
360
try:
361
return self._contains_(self.__ring(x))
362
except TypeError:
363
return False
364
365
def _contains_(self, x):
366
"""
367
Check if ``x``, which is assumed to be in the ambient ring, is in
368
this ideal.
369
370
.. TODO::
371
372
Implement this method.
373
374
EXAMPLES::
375
376
sage: P.<a> = ZZ[]
377
sage: I = P*[a]
378
sage: I._contains_(a)
379
Traceback (most recent call last):
380
...
381
NotImplementedError
382
383
Note that calling ``in`` does not call this method::
384
385
sage: a in I
386
True
387
"""
388
raise NotImplementedError
389
390
def __nonzero__(self):
391
r"""
392
Return ``True`` if this ideal is not `(0)`.
393
394
TESTS::
395
396
sage: I = ZZ.ideal(5)
397
sage: bool(I)
398
True
399
400
::
401
402
sage: I = ZZ['x'].ideal(0)
403
sage: bool(I)
404
False
405
406
::
407
408
sage: I = ZZ['x'].ideal(ZZ['x'].gen()^2)
409
sage: bool(I)
410
True
411
412
::
413
414
sage: I = QQ['x', 'y'].ideal(0)
415
sage: bool(I)
416
False
417
"""
418
for g in self.gens():
419
if not g.is_zero():
420
return True
421
return False
422
423
def base_ring(self):
424
r"""
425
Returns the base ring of this ideal.
426
427
EXAMPLES::
428
429
sage: R = ZZ
430
sage: I = 3*R; I
431
Principal ideal (3) of Integer Ring
432
sage: J = 2*I; J
433
Principal ideal (6) of Integer Ring
434
sage: I.base_ring(); J.base_ring()
435
Integer Ring
436
Integer Ring
437
438
We construct an example of an ideal of a quotient ring::
439
440
sage: R = PolynomialRing(QQ, 'x'); x = R.gen()
441
sage: I = R.ideal(x^2 - 2)
442
sage: I.base_ring()
443
Rational Field
444
445
And `p`-adic numbers::
446
447
sage: R = Zp(7, prec=10); R
448
7-adic Ring with capped relative precision 10
449
sage: I = 7*R; I
450
Principal ideal (7 + O(7^11)) of 7-adic Ring with capped relative precision 10
451
sage: I.base_ring()
452
7-adic Ring with capped relative precision 10
453
"""
454
return self.ring().base_ring()
455
456
def apply_morphism(self, phi):
457
r"""
458
Apply the morphism ``phi`` to every element of this ideal.
459
Returns an ideal in the domain of ``phi``.
460
461
EXAMPLES::
462
463
sage: psi = CC['x'].hom([-CC['x'].0])
464
sage: J = ideal([CC['x'].0 + 1]); J
465
Principal ideal (x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision
466
sage: psi(J)
467
Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision
468
sage: J.apply_morphism(psi)
469
Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision
470
471
::
472
473
sage: psi = ZZ['x'].hom([-ZZ['x'].0])
474
sage: J = ideal([ZZ['x'].0, 2]); J
475
Ideal (x, 2) of Univariate Polynomial Ring in x over Integer Ring
476
sage: psi(J)
477
Ideal (-x, 2) of Univariate Polynomial Ring in x over Integer Ring
478
sage: J.apply_morphism(psi)
479
Ideal (-x, 2) of Univariate Polynomial Ring in x over Integer Ring
480
481
TESTS::
482
483
sage: K.<a> = NumberField(x^2 + 1)
484
sage: A = K.ideal(a)
485
sage: taus = K.embeddings(K)
486
sage: A.apply_morphism(taus[0]) # identity
487
Fractional ideal (a)
488
sage: A.apply_morphism(taus[1]) # complex conjugation
489
Fractional ideal (-a)
490
sage: A.apply_morphism(taus[0]) == A.apply_morphism(taus[1])
491
True
492
493
::
494
495
sage: K.<a> = NumberField(x^2 + 5)
496
sage: B = K.ideal([2, a + 1]); B
497
Fractional ideal (2, a + 1)
498
sage: taus = K.embeddings(K)
499
sage: B.apply_morphism(taus[0]) # identity
500
Fractional ideal (2, a + 1)
501
502
Since 2 is totally ramified, complex conjugation fixes it::
503
504
sage: B.apply_morphism(taus[1]) # complex conjugation
505
Fractional ideal (2, a + 1)
506
sage: taus[1](B)
507
Fractional ideal (2, a + 1)
508
"""
509
from sage.categories.morphism import is_Morphism
510
if not is_Morphism(phi):
511
raise TypeError, "phi must be a morphism"
512
# delegate: morphisms know how to apply themselves to ideals
513
return phi(self)
514
515
def _latex_(self):
516
"""
517
Return a latex representation of ``self``.
518
519
EXAMPLES::
520
521
sage: latex(3*ZZ) # indirect doctest
522
\left(3\right)\Bold{Z}
523
"""
524
return '\\left(%s\\right)%s'%(", ".join([latex.latex(g) for g in \
525
self.gens()]),
526
latex.latex(self.ring()))
527
528
def ring(self):
529
"""
530
Returns the ring containing this ideal.
531
532
EXAMPLES::
533
534
sage: R = ZZ
535
sage: I = 3*R; I
536
Principal ideal (3) of Integer Ring
537
sage: J = 2*I; J
538
Principal ideal (6) of Integer Ring
539
sage: I.ring(); J.ring()
540
Integer Ring
541
Integer Ring
542
543
Note that ``self.ring()`` is different from
544
``self.base_ring()``
545
546
::
547
548
sage: R = PolynomialRing(QQ, 'x'); x = R.gen()
549
sage: I = R.ideal(x^2 - 2)
550
sage: I.base_ring()
551
Rational Field
552
sage: I.ring()
553
Univariate Polynomial Ring in x over Rational Field
554
555
Another example using polynomial rings::
556
557
sage: R = PolynomialRing(QQ, 'x'); x = R.gen()
558
sage: I = R.ideal(x^2 - 3)
559
sage: I.ring()
560
Univariate Polynomial Ring in x over Rational Field
561
sage: Rbar = R.quotient(I, names='a')
562
sage: S = PolynomialRing(Rbar, 'y'); y = Rbar.gen(); S
563
Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3
564
sage: J = S.ideal(y^2 + 1)
565
sage: J.ring()
566
Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3
567
"""
568
return self.__ring
569
570
def reduce(self, f):
571
r"""
572
Return the reduction of the element of `f` modulo ``self``.
573
574
This is an element of `R` that is equivalent modulo `I` to `f` where
575
`I` is ``self``.
576
577
EXAMPLES::
578
579
sage: ZZ.ideal(5).reduce(17)
580
2
581
sage: parent(ZZ.ideal(5).reduce(17))
582
Integer Ring
583
"""
584
return f # default
585
586
def gens(self):
587
"""
588
Return a set of generators / a basis of ``self``.
589
590
This is the set of generators provided during creation of this ideal.
591
592
EXAMPLE::
593
594
sage: P.<x,y> = PolynomialRing(QQ,2)
595
sage: I = Ideal([x,y+1]); I
596
Ideal (x, y + 1) of Multivariate Polynomial Ring in x, y over Rational Field
597
sage: I.gens()
598
[x, y + 1]
599
600
::
601
602
sage: ZZ.ideal(5,10).gens()
603
(5,)
604
"""
605
return self.__gens
606
607
def gen(self, i):
608
"""
609
Return the ``i``-th generator in the current basis of this ideal.
610
611
EXAMPLE::
612
613
sage: P.<x,y> = PolynomialRing(QQ,2)
614
sage: I = Ideal([x,y+1]); I
615
Ideal (x, y + 1) of Multivariate Polynomial Ring in x, y over Rational Field
616
sage: I.gen(1)
617
y + 1
618
619
sage: ZZ.ideal(5,10).gen()
620
5
621
"""
622
return self.__gens[i]
623
624
def ngens(self):
625
"""
626
Return the number of generators in the basis.
627
628
EXAMPLE::
629
630
sage: P.<x,y> = PolynomialRing(QQ,2)
631
sage: I = Ideal([x,y+1]); I
632
Ideal (x, y + 1) of Multivariate Polynomial Ring in x, y over Rational Field
633
sage: I.ngens()
634
2
635
636
sage: ZZ.ideal(5,10).ngens()
637
1
638
"""
639
return len(self.__gens)
640
641
def gens_reduced(self):
642
r"""
643
Same as :meth:`gens()` for this ideal, since there is currently no
644
special ``gens_reduced`` algorithm implemented for this ring.
645
646
This method is provided so that ideals in `\ZZ` have the method
647
``gens_reduced()``, just like ideals of number fields.
648
649
EXAMPLES::
650
651
sage: ZZ.ideal(5).gens_reduced()
652
(5,)
653
"""
654
return self.gens()
655
656
def is_maximal(self):
657
r"""
658
Return ``True`` if the ideal is maximal in the ring containing the
659
ideal.
660
661
.. TODO::
662
663
This is not implemented for many rings. Implement it!
664
665
EXAMPLES::
666
667
sage: R = ZZ
668
sage: I = R.ideal(7)
669
sage: I.is_maximal()
670
True
671
sage: R.ideal(16).is_maximal()
672
False
673
sage: S = Integers(8)
674
sage: S.ideal(0).is_maximal()
675
False
676
sage: S.ideal(2).is_maximal()
677
True
678
sage: S.ideal(4).is_maximal()
679
False
680
"""
681
from sage.rings.all import ZZ
682
R = self.ring()
683
if hasattr(R, 'cover_ring') and R.cover_ring() is ZZ:
684
# The following test only works for quotients of Z/nZ: for
685
# many other rings in Sage, testing whether R/I is a field
686
# is done by testing whether I is maximal, so this would
687
# result in a loop.
688
return R.quotient(self).is_field()
689
kd = R.krull_dimension()
690
if kd == 0 or (kd == 1 and R.is_integral_domain()):
691
# For rings of Krull dimension 0, or for integral domains of
692
# Krull dimension 1, every nontrivial prime ideal is maximal.
693
return self.is_prime()
694
else:
695
raise NotImplementedError
696
697
def is_primary(self, P=None):
698
r"""
699
Returns ``True`` if this ideal is primary (or `P`-primary, if
700
a prime ideal `P` is specified).
701
702
Recall that an ideal `I` is primary if and only if `I` has a
703
unique associated prime (see page 52 in [AtiMac]_). If this
704
prime is `P`, then `I` is said to be `P`-primary.
705
706
INPUT:
707
708
- ``P`` - (default: ``None``) a prime ideal in the same ring
709
710
EXAMPLES::
711
712
sage: R.<x, y> = QQ[]
713
sage: I = R.ideal([x^2, x*y])
714
sage: I.is_primary()
715
False
716
sage: J = I.primary_decomposition()[1]; J
717
Ideal (y, x^2) of Multivariate Polynomial Ring in x, y over Rational Field
718
sage: J.is_primary()
719
True
720
sage: J.is_prime()
721
False
722
723
Some examples from the Macaulay2 documentation::
724
725
sage: R.<x, y, z> = GF(101)[]
726
sage: I = R.ideal([y^6])
727
sage: I.is_primary()
728
True
729
sage: I.is_primary(R.ideal([y]))
730
True
731
sage: I = R.ideal([x^4, y^7])
732
sage: I.is_primary()
733
True
734
sage: I = R.ideal([x*y, y^2])
735
sage: I.is_primary()
736
False
737
738
.. NOTE:
739
740
This uses the list of associated primes.
741
742
REFERENCES:
743
744
.. [AtiMac] Atiyah and Macdonald, "Introduction to commutative
745
algebra", Addison-Wesley, 1969.
746
747
"""
748
try:
749
ass = self.associated_primes()
750
except (NotImplementedError, ValueError):
751
raise NotImplementedError
752
if P is None:
753
return (len(ass) == 1)
754
else:
755
return (len(ass) == 1) and (ass[0] == P)
756
757
758
def primary_decomposition(self):
759
r"""
760
Return a decomposition of this ideal into primary ideals.
761
762
EXAMPLES::
763
764
sage: R = ZZ[x]
765
sage: I = R.ideal(7)
766
sage: I.primary_decomposition()
767
Traceback (most recent call last):
768
...
769
NotImplementedError
770
"""
771
raise NotImplementedError
772
773
def is_prime(self):
774
r"""
775
Return ``True`` if this ideal is prime.
776
777
EXAMPLES::
778
779
sage: R.<x, y> = QQ[]
780
sage: I = R.ideal([x, y])
781
sage: I.is_prime() # a maximal ideal
782
True
783
sage: I = R.ideal([x^2-y])
784
sage: I.is_prime() # a non-maximal prime ideal
785
True
786
sage: I = R.ideal([x^2, y])
787
sage: I.is_prime() # a non-prime primary ideal
788
False
789
sage: I = R.ideal([x^2, x*y])
790
sage: I.is_prime() # a non-prime non-primary ideal
791
False
792
793
sage: S = Integers(8)
794
sage: S.ideal(0).is_prime()
795
False
796
sage: S.ideal(2).is_prime()
797
True
798
sage: S.ideal(4).is_prime()
799
False
800
801
Note that this method is not implemented for all rings where it
802
could be::
803
804
sage: R = ZZ[x]
805
sage: I = R.ideal(7)
806
sage: I.is_prime() # when implemented, should be True
807
Traceback (most recent call last):
808
...
809
NotImplementedError
810
811
.. NOTE::
812
813
For general rings, uses the list of associated primes.
814
"""
815
from sage.rings.all import ZZ
816
R = self.ring()
817
if hasattr(R, 'cover_ring') and R.cover_ring() is ZZ and R.is_finite():
818
# For quotient rings of ZZ, prime is the same as maximal.
819
return self.is_maximal()
820
try:
821
ass = self.associated_primes()
822
except (NotImplementedError, ValueError):
823
raise NotImplementedError
824
if len(ass) != 1:
825
return False
826
if self == ass[0]:
827
return True
828
else:
829
return False
830
831
def associated_primes(self):
832
r"""
833
Return the list of associated prime ideals of this ideal.
834
835
EXAMPLES::
836
837
sage: R = ZZ[x]
838
sage: I = R.ideal(7)
839
sage: I.associated_primes()
840
Traceback (most recent call last):
841
...
842
NotImplementedError
843
"""
844
raise NotImplementedError
845
846
def minimal_associated_primes(self):
847
r"""
848
Return the list of minimal associated prime ideals of this ideal.
849
850
EXAMPLES::
851
852
sage: R = ZZ[x]
853
sage: I = R.ideal(7)
854
sage: I.minimal_associated_primes()
855
Traceback (most recent call last):
856
...
857
NotImplementedError
858
"""
859
raise NotImplementedError
860
861
def embedded_primes(self):
862
r"""
863
Return the list of embedded primes of this ideal.
864
865
EXAMPLES::
866
867
sage: R.<x, y> = QQ[]
868
sage: I = R.ideal(x^2, x*y)
869
sage: I.embedded_primes()
870
[Ideal (y, x) of Multivariate Polynomial Ring in x, y over Rational Field]
871
"""
872
# by definition, embedded primes are associated primes that
873
# are not minimal (under inclusion)
874
ass = self.associated_primes()
875
min_ass = self.minimal_associated_primes()
876
emb = []
877
for p in ass:
878
try:
879
i = min_ass.index(p)
880
except ValueError:
881
emb.append(p)
882
emb.sort()
883
return emb
884
885
def is_principal(self):
886
r"""
887
Returns ``True`` if the ideal is principal in the ring containing the
888
ideal.
889
890
.. TODO::
891
892
Code is naive. Only keeps track of ideal generators as set
893
during initialization of the ideal. (Can the base ring change? See
894
example below.)
895
896
EXAMPLES::
897
898
sage: R = ZZ[x]
899
sage: I = R.ideal(2,x)
900
sage: I.is_principal()
901
Traceback (most recent call last):
902
...
903
NotImplementedError
904
sage: J = R.base_extend(QQ).ideal(2,x)
905
sage: J.is_principal()
906
True
907
"""
908
if len(self.gens()) <= 1:
909
return True
910
raise NotImplementedError
911
912
def is_trivial(self):
913
r"""
914
Return ``True`` if this ideal is `(0)` or `(1)`.
915
916
TESTS::
917
918
sage: I = ZZ.ideal(5)
919
sage: I.is_trivial()
920
False
921
922
::
923
924
sage: I = ZZ['x'].ideal(-1)
925
sage: I.is_trivial()
926
True
927
928
::
929
930
sage: I = ZZ['x'].ideal(ZZ['x'].gen()^2)
931
sage: I.is_trivial()
932
False
933
934
::
935
936
sage: I = QQ['x', 'y'].ideal(-5)
937
sage: I.is_trivial()
938
True
939
940
::
941
942
sage: I = CC['x'].ideal(0)
943
sage: I.is_trivial()
944
True
945
"""
946
if self.is_zero():
947
return True
948
# If self is principal, can give a complete answer
949
if self.is_principal():
950
return self.gens()[0].is_unit()
951
# If self is not principal, can only give an affirmative answer
952
for g in self.gens():
953
if g.is_unit():
954
return True
955
raise NotImplementedError
956
957
def category(self):
958
"""
959
Return the category of this ideal.
960
961
.. NOTE::
962
963
category is dependent on the ring of the ideal.
964
965
EXAMPLES::
966
967
sage: I = ZZ.ideal(7)
968
sage: J = ZZ[x].ideal(7,x)
969
sage: K = ZZ[x].ideal(7)
970
sage: I.category()
971
Category of ring ideals in Integer Ring
972
sage: J.category()
973
Category of ring ideals in Univariate Polynomial Ring in x
974
over Integer Ring
975
sage: K.category()
976
Category of ring ideals in Univariate Polynomial Ring in x
977
over Integer Ring
978
"""
979
import sage.categories.all
980
return sage.categories.all.Ideals(self.__ring)
981
982
def __add__(self, other):
983
"""
984
Add ``self`` on the left to ``other``.
985
986
This makes sure that ``other`` and ``self`` are in the same rings.
987
988
EXAMPLES::
989
990
sage: P.<x,y,z> = QQ[]
991
sage: I = [x + y]*P
992
sage: I + [y + z]
993
Ideal (x + y, y + z) of Multivariate Polynomial Ring in x, y, z over Rational Field
994
"""
995
if not isinstance(other, Ideal_generic):
996
other = self.ring().ideal(other)
997
return self.ring().ideal(self.gens() + other.gens())
998
999
def __radd__(self, other):
1000
"""
1001
Add ``self`` on the right to ``other``.
1002
1003
This makes sure that ``other`` and ``self`` are in the same rings.
1004
1005
EXAMPLES::
1006
1007
sage: P.<x,y,z> = QQ[]
1008
sage: I = [x + y]*P
1009
sage: [y + z] + I
1010
Ideal (x + y, y + z) of Multivariate Polynomial Ring in x, y, z over Rational Field
1011
"""
1012
if not isinstance(other, Ideal_generic):
1013
other = self.ring().ideal(other)
1014
return self.ring().ideal(self.gens() + other.gens())
1015
1016
def __mul__(self, other):
1017
"""
1018
This method just makes sure that ``self`` and other are ideals in the
1019
same ring and then calls :meth:`_mul_`. If you want to change the
1020
behaviour of ideal multiplication in a subclass of
1021
:class:`Ideal_generic` please overwrite :meth:`_mul_` and not
1022
:meth:`__mul__`.
1023
1024
EXAMPLE::
1025
1026
sage: P.<x,y,z> = QQ[]
1027
sage: I = [x*y + y*z, x^2 + x*y - y*x - y^2] * P
1028
sage: I * 2 # indirect doctest
1029
Ideal (2*x*y + 2*y*z, 2*x^2 - 2*y^2) of Multivariate Polynomial Ring in x, y, z over Rational Field
1030
"""
1031
if not isinstance(other, Ideal_generic):
1032
try:
1033
if self.ring().has_coerce_map_from(other):
1034
return self
1035
except (TypeError,ArithmeticError,ValueError):
1036
pass
1037
other = self.ring().ideal(other)
1038
return self._mul_(other)
1039
1040
def _mul_(self, other):
1041
"""
1042
This is a very general implementation of Ideal multiplication.
1043
1044
This method assumes that ``self`` and ``other`` are Ideals of the
1045
same ring.
1046
1047
The number of generators of ```self * other` will be
1048
``self.ngens() * other.ngens()``. So if used repeatedly this method
1049
will create an ideal with a uselessly large amount of generators.
1050
Therefore it is advisable to overwrite this method with a method that
1051
takes advantage of the structure of the ring your working in.
1052
1053
Example::
1054
1055
sage: P.<x,y,z> = QQ[]
1056
sage: I=P.ideal([x*y, x*z, x^2])
1057
sage: J=P.ideal([x^2, x*y])
1058
sage: I._mul_(J)
1059
Ideal (x^3*y, x^2*y^2, x^3*z, x^2*y*z, x^4, x^3*y) of Multivariate Polynomial Ring in x, y, z over Rational Field
1060
"""
1061
return self.ring().ideal([z for z in [x*y for x in self.gens() for y in other.gens()] if z])
1062
1063
def __rmul__(self, other):
1064
"""
1065
Multiply ``self`` on the right with ``other``.
1066
1067
EXAMPLE::
1068
1069
sage: P.<x,y,z> = QQ[]
1070
sage: I = [x*y+y*z,x^2+x*y-y*x-y^2]*P
1071
sage: [2]*I # indirect doctest
1072
Ideal (2*x*y + 2*y*z, 2*x^2 - 2*y^2) of Multivariate Polynomial Ring in x, y, z over Rational Field
1073
1074
"""
1075
if not isinstance(other, Ideal_generic):
1076
try:
1077
if self.ring().has_coerce_map_from(other):
1078
return self
1079
except (TypeError,ArithmeticError,ValueError):
1080
pass
1081
other = self.ring().ideal(other)
1082
return self.ring().ideal([z for z in [y*x for x in self.gens() for y in other.gens()] if z])
1083
1084
def norm(self):
1085
"""
1086
Returns the norm of this ideal.
1087
1088
In the general case, this is just the ideal itself, since the ring it
1089
lies in can't be implicitly assumed to be an extension of anything.
1090
1091
We include this function for compatibility with cases such as ideals in
1092
number fields.
1093
1094
EXAMPLES::
1095
1096
sage: R.<t> = GF(8, names='a')[]
1097
sage: I = R.ideal(t^4 + t + 1)
1098
sage: I.norm()
1099
Principal ideal (t^4 + t + 1) of Univariate Polynomial Ring in t over Finite Field in a of size 2^3
1100
"""
1101
return self
1102
1103
def absolute_norm(self):
1104
"""
1105
Returns the absolute norm of this ideal.
1106
1107
In the general case, this is just the ideal itself, since the ring it
1108
lies in can't be implicitly assumed to be an extension of anything.
1109
1110
We include this function for compatibility with cases such as ideals in
1111
number fields.
1112
1113
.. TODO::
1114
1115
Implement this method.
1116
1117
EXAMPLES::
1118
1119
sage: R.<t> = GF(9, names='a')[]
1120
sage: I = R.ideal(t^4 + t + 1)
1121
sage: I.absolute_norm()
1122
Traceback (most recent call last):
1123
...
1124
NotImplementedError
1125
"""
1126
raise NotImplementedError
1127
1128
class Ideal_principal(Ideal_generic):
1129
"""
1130
A principal ideal.
1131
1132
See :func:`Ideal()`.
1133
"""
1134
# now Ideal_principal takes a list.
1135
#def __init__(self, ring, gen):
1136
# Ideal_generic.__init__(self, ring, [gen])
1137
1138
def __repr__(self):
1139
"""
1140
Return a string representation of ``self``.
1141
1142
EXAMPLES::
1143
1144
sage: R = ZZ[x]
1145
sage: I = R.ideal(x)
1146
sage: I # indirect doctest
1147
Principal ideal (x) of Univariate Polynomial Ring in x over Integer Ring
1148
"""
1149
return "Principal ideal (%s) of %s"%(self.gen(), self.ring())
1150
1151
def is_principal(self):
1152
r"""
1153
Returns ``True`` if the ideal is principal in the ring containing the
1154
ideal. When the ideal construction is explicitly principal (i.e.
1155
when we define an ideal with one element) this is always the case.
1156
1157
EXAMPLES:
1158
1159
Note that Sage automatically coerces ideals into
1160
principal ideals during initialization::
1161
1162
sage: R = ZZ[x]
1163
sage: I = R.ideal(x)
1164
sage: J = R.ideal(2,x)
1165
sage: K = R.base_extend(QQ).ideal(2,x)
1166
sage: I
1167
Principal ideal (x) of Univariate Polynomial Ring in x
1168
over Integer Ring
1169
sage: J
1170
Ideal (2, x) of Univariate Polynomial Ring in x over Integer Ring
1171
sage: K
1172
Principal ideal (1) of Univariate Polynomial Ring in x
1173
over Rational Field
1174
sage: I.is_principal()
1175
True
1176
sage: K.is_principal()
1177
True
1178
"""
1179
return True
1180
1181
def gen(self):
1182
r"""
1183
Returns the generator of the principal ideal. The generators are
1184
elements of the ring containing the ideal.
1185
1186
EXAMPLES:
1187
1188
A simple example in the integers::
1189
1190
sage: R = ZZ
1191
sage: I = R.ideal(7)
1192
sage: J = R.ideal(7, 14)
1193
sage: I.gen(); J.gen()
1194
7
1195
7
1196
1197
Note that the generator belongs to the ring from which the ideal
1198
was initialized::
1199
1200
sage: R = ZZ[x]
1201
sage: I = R.ideal(x)
1202
sage: J = R.base_extend(QQ).ideal(2,x)
1203
sage: a = I.gen(); a
1204
x
1205
sage: b = J.gen(); b
1206
1
1207
sage: a.base_ring()
1208
Integer Ring
1209
sage: b.base_ring()
1210
Rational Field
1211
"""
1212
return self.gens()[0]
1213
1214
def __contains__(self, x):
1215
"""
1216
Return ``True`` if ``x`` is in ``self``.
1217
1218
EXAMPLES::
1219
1220
sage: P.<x> = PolynomialRing(ZZ)
1221
sage: I = P.ideal(x^2-2)
1222
sage: x^2 in I
1223
False
1224
sage: x^2-2 in I
1225
True
1226
sage: x^2-3 in I
1227
False
1228
"""
1229
if self.gen().is_zero():
1230
return x.is_zero()
1231
return self.gen().divides(x)
1232
1233
def __cmp__(self, other):
1234
"""
1235
Compare the two ideals.
1236
1237
EXAMPLE:
1238
1239
Comparision with non-principal ideal::
1240
1241
sage: P.<x, y> = PolynomialRing(ZZ)
1242
sage: I = P.ideal(x^2)
1243
sage: J = [x, y^2 + x*y]*P
1244
sage: cmp(I, J) # indirect doctest
1245
1
1246
1247
Between two principal ideals::
1248
1249
sage: P.<x> = PolynomialRing(ZZ)
1250
sage: I = P.ideal(x^2-2)
1251
sage: I2 = P.ideal(0)
1252
sage: I2.is_zero()
1253
True
1254
sage: cmp(I2, I)
1255
-1
1256
sage: I3 = P.ideal(x)
1257
sage: cmp(I, I3)
1258
1
1259
"""
1260
if not isinstance(other, Ideal_generic):
1261
other = self.ring().ideal(other)
1262
1263
if not other.is_principal():
1264
return -1
1265
1266
if self.is_zero():
1267
if not other.is_zero():
1268
return -1
1269
return 0
1270
1271
# is other.gen() / self.gen() a unit in the base ring?
1272
g0 = other.gen()
1273
g1 = self.gen()
1274
if g0.divides(g1) and g1.divides(g0):
1275
return 0
1276
return 1
1277
1278
def divides(self, other):
1279
"""
1280
Return ``True`` if ``self`` divides ``other``.
1281
1282
EXAMPLES::
1283
1284
sage: P.<x> = PolynomialRing(QQ)
1285
sage: I = P.ideal(x)
1286
sage: J = P.ideal(x^2)
1287
sage: I.divides(J)
1288
True
1289
sage: J.divides(I)
1290
False
1291
"""
1292
if isinstance(other, Ideal_principal):
1293
return self.gen().divides(other.gen())
1294
raise NotImplementedError
1295
1296
class Ideal_pid(Ideal_principal):
1297
"""
1298
An ideal of a principal ideal domain.
1299
1300
See :func:`Ideal()`.
1301
"""
1302
def __init__(self, ring, gen):
1303
"""
1304
Initialize ``self``.
1305
1306
EXAMPLES::
1307
1308
sage: I = 8*ZZ
1309
sage: I
1310
Principal ideal (8) of Integer Ring
1311
"""
1312
Ideal_principal.__init__(self, ring, gen)
1313
1314
def __add__(self, other):
1315
"""
1316
Add the two ideals.
1317
1318
EXAMPLES::
1319
1320
sage: I = 8*ZZ
1321
sage: I2 = 3*ZZ
1322
sage: I + I2
1323
Principal ideal (1) of Integer Ring
1324
"""
1325
if not isinstance(other, Ideal_generic):
1326
other = self.ring().ideal(other)
1327
return self.ring().ideal(self.gcd(other))
1328
1329
def reduce(self, f):
1330
"""
1331
Return the reduction of `f` modulo ``self``.
1332
1333
EXAMPLES::
1334
1335
sage: I = 8*ZZ
1336
sage: I.reduce(10)
1337
2
1338
sage: n = 10; n.mod(I)
1339
2
1340
"""
1341
f = self.ring()(f)
1342
if self.gen() == 0:
1343
return f
1344
q, r = f.quo_rem(self.gen())
1345
return r
1346
1347
def gcd(self, other):
1348
r"""
1349
Returns the greatest common divisor of the principal ideal with the
1350
ideal ``other``; that is, the largest principal ideal
1351
contained in both the ideal and ``other``
1352
1353
.. TODO:
1354
1355
This is not implemented in the case when ``other`` is neither
1356
principal nor when the generator of ``self`` is contained in
1357
``other``. Also, it seems that this class is used only in PIDs--is
1358
this redundant?
1359
1360
.. NOTE:
1361
1362
The second example is broken.
1363
1364
EXAMPLES:
1365
1366
An example in the principal ideal domain `\ZZ`::
1367
1368
sage: R = ZZ
1369
sage: I = R.ideal(42)
1370
sage: J = R.ideal(70)
1371
sage: I.gcd(J)
1372
Principal ideal (14) of Integer Ring
1373
sage: J.gcd(I)
1374
Principal ideal (14) of Integer Ring
1375
1376
TESTS:
1377
1378
We cannot take the gcd of a principal ideal with a
1379
non-principal ideal as well: ( ``gcd(I,J)`` should be `(7)` )
1380
1381
::
1382
1383
sage: I = ZZ.ideal(7)
1384
sage: J = ZZ[x].ideal(7,x)
1385
sage: I.gcd(J)
1386
Traceback (most recent call last):
1387
...
1388
NotImplementedError
1389
sage: J.gcd(I)
1390
Traceback (most recent call last):
1391
...
1392
AttributeError: 'Ideal_generic' object has no attribute 'gcd'
1393
1394
Note::
1395
1396
sage: type(I)
1397
<class 'sage.rings.ideal.Ideal_pid'>
1398
sage: type(J)
1399
<class 'sage.rings.ideal.Ideal_generic'>
1400
"""
1401
if isinstance(other, Ideal_principal):
1402
return self.ring().ideal(self.gen().gcd(other.gen()))
1403
elif self.gen() in other:
1404
return other
1405
else:
1406
raise NotImplementedError
1407
1408
def is_prime(self):
1409
"""
1410
Return ``True`` if the ideal is prime.
1411
1412
This relies on the ring elements having a method ``is_irreducible()``
1413
implemented, since an ideal `(a)` is prime iff `a` is irreducible
1414
(or 0).
1415
1416
EXAMPLES::
1417
1418
sage: ZZ.ideal(2).is_prime()
1419
True
1420
sage: ZZ.ideal(-2).is_prime()
1421
True
1422
sage: ZZ.ideal(4).is_prime()
1423
False
1424
sage: ZZ.ideal(0).is_prime()
1425
True
1426
sage: R.<x>=QQ[]
1427
sage: P=R.ideal(x^2+1); P
1428
Principal ideal (x^2 + 1) of Univariate Polynomial Ring in x over Rational Field
1429
sage: P.is_prime()
1430
True
1431
"""
1432
if self.is_zero(): # PIDs are integral domains by definition
1433
return True
1434
g = self.gen()
1435
if hasattr(g, 'is_irreducible'):
1436
return g.is_irreducible()
1437
1438
raise NotImplementedError
1439
1440
def is_maximal(self):
1441
"""
1442
Returns whether this ideal is maximal.
1443
1444
Principal ideal domains have Krull dimension 1 (or 0), so an ideal is
1445
maximal if and only if it's prime (and nonzero if the ring is not a
1446
field).
1447
1448
EXAMPLES::
1449
1450
sage: R.<t> = GF(5)[]
1451
sage: p = R.ideal(t^2 + 2)
1452
sage: p.is_maximal()
1453
True
1454
sage: p = R.ideal(t^2 + 1)
1455
sage: p.is_maximal()
1456
False
1457
sage: p = R.ideal(0)
1458
sage: p.is_maximal()
1459
False
1460
sage: p = R.ideal(1)
1461
sage: p.is_maximal()
1462
False
1463
"""
1464
if not self.ring().is_field() and self.is_zero():
1465
return False
1466
return self.is_prime()
1467
1468
def residue_field(self):
1469
r"""
1470
Return the residue class field of this ideal, which must be prime.
1471
1472
.. TODO:
1473
1474
Implement this for more general rings. Currently only defined
1475
for `\ZZ` and for number field orders.
1476
1477
EXAMPLES::
1478
1479
sage: P = ZZ.ideal(61); P
1480
Principal ideal (61) of Integer Ring
1481
sage: F = P.residue_field(); F
1482
Residue field of Integers modulo 61
1483
sage: pi = F.reduction_map(); pi
1484
Partially defined reduction map:
1485
From: Rational Field
1486
To: Residue field of Integers modulo 61
1487
sage: pi(123/234)
1488
6
1489
sage: pi(1/61)
1490
Traceback (most recent call last):
1491
...
1492
ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation
1493
sage: lift = F.lift_map(); lift
1494
Lifting map:
1495
From: Residue field of Integers modulo 61
1496
To: Integer Ring
1497
sage: lift(F(12345/67890))
1498
33
1499
sage: (12345/67890) % 61
1500
33
1501
1502
TESTS::
1503
1504
sage: ZZ.ideal(96).residue_field()
1505
Traceback (most recent call last):
1506
...
1507
ValueError: The ideal (Principal ideal (96) of Integer Ring) is not prime
1508
1509
::
1510
1511
sage: R.<x>=QQ[]
1512
sage: I=R.ideal(x^2+1)
1513
sage: I.is_prime()
1514
True
1515
sage: I.residue_field()
1516
Traceback (most recent call last):
1517
...
1518
TypeError: residue fields only supported for polynomial rings over finite fields.
1519
"""
1520
if not self.is_prime():
1521
raise ValueError, "The ideal (%s) is not prime"%self
1522
from sage.rings.integer_ring import ZZ
1523
if self.ring() is ZZ:
1524
return ZZ.residue_field(self, check = False)
1525
raise NotImplementedError, "residue_field() is only implemented for ZZ and rings of integers of number fields."
1526
1527
class Ideal_fractional(Ideal_generic):
1528
"""
1529
Fractional ideal of a ring.
1530
1531
See :func:`Ideal()`.
1532
"""
1533
def __repr__(self):
1534
"""
1535
Return a string representation of ``self``.
1536
1537
EXAMPLES::
1538
1539
sage: from sage.rings.ideal import Ideal_fractional
1540
sage: K.<a> = NumberField(x^2 + 1)
1541
sage: Ideal_fractional(K, [a]) # indirect doctest
1542
Fractional ideal (a) of Number Field in a with defining polynomial x^2 + 1
1543
"""
1544
return "Fractional ideal %s of %s"%(self._repr_short(), self.ring())
1545
1546
# constructors for standard (benchmark) ideals, written uppercase as
1547
# these are constructors
1548
1549
def Cyclic(R, n=None, homog=False, singular=singular_default):
1550
"""
1551
Ideal of cyclic ``n``-roots from 1-st ``n`` variables of ``R`` if ``R`` is
1552
coercible to :class:`Singular <sage.interfaces.singular.Singular>`.
1553
1554
INPUT:
1555
1556
- ``R`` -- base ring to construct ideal for
1557
1558
- ``n`` -- number of cyclic roots (default: ``None``). If ``None``, then
1559
``n`` is set to ``R.ngens()``.
1560
1561
- ``homog`` -- (default: ``False``) if ``True`` a homogeneous ideal is
1562
returned using the last variable in the ideal
1563
1564
- ``singular`` -- singular instance to use
1565
1566
.. NOTE::
1567
1568
``R`` will be set as the active ring in
1569
:class:`Singular <sage.interfaces.singular.Singular>`
1570
1571
EXAMPLES:
1572
1573
An example from a multivariate polynomial ring over the
1574
rationals::
1575
1576
sage: P.<x,y,z> = PolynomialRing(QQ,3,order='lex')
1577
sage: I = sage.rings.ideal.Cyclic(P)
1578
sage: I
1579
Ideal (x + y + z, x*y + x*z + y*z, x*y*z - 1) of Multivariate Polynomial
1580
Ring in x, y, z over Rational Field
1581
sage: I.groebner_basis()
1582
[x + y + z, y^2 + y*z + z^2, z^3 - 1]
1583
1584
We compute a Groebner basis for cyclic 6, which is a standard
1585
benchmark and test ideal::
1586
1587
sage: R.<x,y,z,t,u,v> = QQ['x,y,z,t,u,v']
1588
sage: I = sage.rings.ideal.Cyclic(R,6)
1589
sage: B = I.groebner_basis()
1590
sage: len(B)
1591
45
1592
"""
1593
from rational_field import RationalField
1594
1595
if n:
1596
if n > R.ngens():
1597
raise ArithmeticError, "n must be <= R.ngens()"
1598
else:
1599
n = R.ngens()
1600
1601
singular.lib("poly")
1602
R2 = R.change_ring(RationalField())
1603
R2._singular_().set_ring()
1604
1605
if not homog:
1606
I = singular.cyclic(n)
1607
else:
1608
I = singular.cyclic(n).homog(R2.gen(n-1))
1609
return R2.ideal(I).change_ring(R)
1610
1611
def Katsura(R, n=None, homog=False, singular=singular_default):
1612
"""
1613
``n``-th katsura ideal of ``R`` if ``R`` is coercible to
1614
:class:`Singular <sage.interfaces.singular.Singular>`.
1615
1616
INPUT:
1617
1618
- ``R`` -- base ring to construct ideal for
1619
1620
- ``n`` -- (default: ``None``) which katsura ideal of ``R``. If ``None``,
1621
then ``n`` is set to ``R.ngens()``.
1622
1623
- ``homog`` -- if ``True`` a homogeneous ideal is returned
1624
using the last variable in the ideal (default: ``False``)
1625
1626
- ``singular`` -- singular instance to use
1627
1628
1629
EXAMPLES::
1630
1631
sage: P.<x,y,z> = PolynomialRing(QQ,3)
1632
sage: I = sage.rings.ideal.Katsura(P,3); I
1633
Ideal (x + 2*y + 2*z - 1, x^2 + 2*y^2 + 2*z^2 - x, 2*x*y + 2*y*z - y)
1634
of Multivariate Polynomial Ring in x, y, z over Rational Field
1635
1636
::
1637
1638
sage: Q.<x> = PolynomialRing(QQ,1)
1639
sage: J = sage.rings.ideal.Katsura(Q,1); J
1640
Ideal (x - 1) of Multivariate Polynomial Ring in x over Rational Field
1641
"""
1642
from rational_field import RationalField
1643
if n:
1644
if n > R.ngens():
1645
raise ArithmeticError, "n must be <= R.ngens()."
1646
else:
1647
n = R.ngens()
1648
singular.lib("poly")
1649
R2 = R.change_ring(RationalField())
1650
R2._singular_().set_ring()
1651
1652
if not homog:
1653
I = singular.katsura(n)
1654
else:
1655
I = singular.katsura(n).homog(R2.gen(n-1))
1656
return R2.ideal(I).change_ring(R)
1657
1658
def FieldIdeal(R):
1659
r"""
1660
Let ``q = R.base_ring().order()`` and `(x_0,...,x_n)` ``= R.gens()`` then
1661
if `q` is finite this constructor returns
1662
1663
.. MATH::
1664
1665
\langle x_0^q - x_0, ... , x_n^q - x_n \rangle.
1666
1667
We call this ideal the field ideal and the generators the field
1668
equations.
1669
1670
EXAMPLES:
1671
1672
The field ideal generated from the polynomial ring over
1673
two variables in the finite field of size 2::
1674
1675
sage: P.<x,y> = PolynomialRing(GF(2),2)
1676
sage: I = sage.rings.ideal.FieldIdeal(P); I
1677
Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y over
1678
Finite Field of size 2
1679
1680
Another, similar example::
1681
1682
sage: Q.<x1,x2,x3,x4> = PolynomialRing(GF(2^4,name='alpha'), 4)
1683
sage: J = sage.rings.ideal.FieldIdeal(Q); J
1684
Ideal (x1^16 + x1, x2^16 + x2, x3^16 + x3, x4^16 + x4) of
1685
Multivariate Polynomial Ring in x1, x2, x3, x4 over Finite
1686
Field in alpha of size 2^4
1687
"""
1688
1689
q = R.base_ring().order()
1690
1691
if q is sage.rings.infinity.infinity:
1692
raise TypeError, "Cannot construct field ideal for R.base_ring().order()==infinity"
1693
1694
return R.ideal([x**q - x for x in R.gens() ])
1695
1696