# comparison of ideals

What does the output mean when you type A<=B where A and B are ideals in a polynomial ring?

comparison of ideals

What does the output mean when you type A<=B where A and B are ideals in a polynomial ring?

add a comment

3

To find out, you can look in the __cmp__ special method of the object you're interested in. This function returns negative if `x<y`

, zero if `x==y`

, and positive if `x>y`

. Looking in __cmp__ interactively is probably a better idea than browsing the source, because if you do that you may guess wrong about which __cmp__ is being used (like I did!).

For example:

```
sage: P.<x> = PolynomialRing(QQ)
sage: I = Ideal([x^2-2*x+1, x^2-1])
sage: J = Ideal([4 + 3*x + x^2, 1 + x^2])
sage: I.__cmp__??
Type: instancemethod
Base Class: <type 'instancemethod'>
String Form: <bound method Ideal_1poly_field.__cmp__ of Principal ideal (x - 1) of Univariate Polynomial Ring in x over Rational Field>
Namespace: Interactive
File: /Applications/sage/local/lib/python2.6/site-packages/sage/rings/ideal.py
Definition: I.__cmp__(self, other)
Source:
def __cmp__(self, other):
if not isinstance(other, Ideal_generic):
other = self.ring().ideal(other)
if not other.is_principal():
return -1
if self.is_zero():
if not other.is_zero():
return -1
return 0
# is other.gen() / self.gen() a unit in the base ring?
g0 = other.gen()
g1 = self.gen()
if g0.divides(g1) and g1.divides(g0):
return 0
return 1
sage: I.gen(), J.gen()
(x - 1, 1)
sage: I == J, I <= J, I >= J
(False, False, True)
sage: # or exactly the same case but now (potentially) multivariate
sage: P.<x,y> = PolynomialRing(QQ,2)
sage: I = Ideal([x^2-2*x+1, x^2-1])
sage: J = Ideal([4 + 3*x + x^2, 1 + x^2])
sage: I.__cmp__??
[docstring removed]
# first check the type
if not isinstance(other, MPolynomialIdeal):
return 1
# the ideals may be defined w.r.t. to different term orders
# but are still the same.
R = self.ring()
S = other.ring()
if R is not S: # rings are unique
if type(R) == type(S) and (R.base_ring() == S.base_ring()) and (R.ngens() == S.ngens()):
other = other.change_ring(R)
else:
return cmp((type(R), R.base_ring(), R.ngens()), (type(S), S.base_ring(), S.ngens()))
# now, check whether the GBs are cached already
if self.groebner_basis.is_in_cache() and other.groebner_basis.is_in_cache():
l = self.groebner_basis()
r = other.groebner_basis()
else: # use easy GB otherwise
try:
l = self.change_ring(R.change_ring(order="degrevlex")).groebner_basis()
r = other.change_ring(R.change_ring(order="degrevlex")).groebner_basis()
except AttributeError: # e.g. quotient rings
l = self.groebner_basis()
r = other.groebner_basis()
return cmp(l,r)
sage: I.groebner_basis(), J.groebner_basis()
([x - 1], [1])
```

sage: I == J, I <= J, I >= J (False, False, True)

So it seems (modulo some details) it's basically comparing the Sequences of the groebner bases, and that appears to fall through to simply sorting the underlying lists of polynomials. I don't know how useful that is, but that looks like what it's doing.

Oh no, that does not seem useful. Thank you for your response. Now I am doubting that A==B being True even means that the ideals are equal, which I was assuming. Does sage have built in functions for ideal equality and ideal containment? I would like to have a function like equality(A,B) and containment(A,B) whose value being true means A=B as ideal and A is contained in B, respectively? Does such a function exist? I know I can compute reduced Grob bases of both ideals and visually check if they are the same but I would like have a sage function that will check that for me.

IIUC the above logic should get equality right, so if that's all you need you're set. (It'd be a bug if it doesn't!) I'm a little rusty, but I gather you'd like A <= B iff all the terms in the generators of A (or the fewer but more expensive to compute terms in the groebner basis) are contained in B? If so, would something like def containment(A, B): return all(gen in B for gen in A.gens()) or def containment(A, B): return all(gb in B for gb in A.groebner_basis()) work?

Yes, that is right. I just need a function that checks if all the generators of A are contained in the ideal B. Easy enough, and I think your costom function does work but I am wondering if there is a predefined sage function(command) that does this or if I have to define one.

Please start posting anonymously - your entry will be published after you log in or create a new account.

Asked: ** 2011-01-19 22:37:05 +0200 **

Seen: **1,043 times**

Last updated: **Jan 19 '11**

Matrix conjugacy classes over Z and ideal classes

reducing ideal wrt another ideal

Find polynomial in terms of ideal

memory leak when doing lots of ideal tests

Explicit representation of element of ideal

Find specific linear combination in multivariate polynomial ring

Non-homogenous Ideals In Unital Associative Free Algebras

Why do messages "// ** redefining ..." show up when computing the dimension of an ideal?

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.