ideal intersection in ZZ

84 views
Skip to first unread message

G. M.-S.

unread,
Oct 28, 2023, 5:36:51 AM10/28/23
to sage-s...@googlegroups.com

I wonder why SageMath cannot compute the intersection of 2 ideals in ZZ.

Is this due to the fact that ZZ would "only" be a PID?

Guillermo

┌────────────────────────────────────────────────────────────────────┐

│ SageMath version 10.1, Release Date: 2023-08-20                   

│ Using Python 3.11.1. Type "help()" for help.                      

└────────────────────────────────────────────────────────────────────┘

sage: n1,n2=720,756

sage: d,m=gcd(n1,n2),lcm(n1,n2)

sage: n1,n2,d,m

(720, 756, 36, 15120)

sage: I1,I2=ZZ.ideal(n1),ZZ.ideal(n2)

sage: I1,I2

(Principal ideal (720) of Integer Ring, Principal ideal (756) of Integer Ring)

sage: I1+I2

Principal ideal (36) of Integer Ring

sage: I1.intersection(I2)

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

Cell In [7], line 1

----> 1 I1.intersection(I2)


File /private/var/tmp/sage-10.1-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/structure/element.pyx:488, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4846)()

    486         AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'

    487     """

--> 488     return self.getattr_from_category(name)

    489 

    490 cdef getattr_from_category(self, name):


File /private/var/tmp/sage-10.1-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/structure/element.pyx:501, in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4958)()

    499     else:

    500         cls = P._abstract_element_class

--> 501     return getattr_from_other_class(self, cls, name)

    502 

    503 def __dir__(self):


File /private/var/tmp/sage-10.1-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/cpython/getattr.pyx:362, in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2773)()

    360     dummy_error_message.cls = type(self)

    361     dummy_error_message.name = name

--> 362     raise AttributeError(dummy_error_message)

    363 attribute = <object>attr

    364 # Check for a descriptor (__get__ in Python)


AttributeError: 'Ideal_pid' object has no attribute 'intersection'

sage: 


Nils Bruin

unread,
Oct 28, 2023, 12:44:55 PM10/28/23
to sage-support
I'm sure its omission is just an oversight. For fractional ideals in number fields it is defined:

sage: K.<r>=QuadraticField(7)
sage: I=K.fractional_ideal(5)
sage: J=K.fractional_ideal(3)
sage: I.intersection(J)
Fractional ideal (15)

I doubt that just knowing a ring is a PID makes computing intersections of ideals easy. So the omission may be because there doesn't seem to be ZZ-specific (or euclidean ring-specific) ideal code. And with lcm around, the need for it has been low, I expect.

G. M.-S.

unread,
Oct 28, 2023, 1:22:15 PM10/28/23
to sage-s...@googlegroups.com

Thanks, Nils.

My question was motivated by using SageMath in my teachings.

Do you think it would be difficult/worthwhile taking care of this?
I mean, ideals in euclidean rings (or at least in ZZ).

Guillermo

Nils Bruin

unread,
Oct 28, 2023, 2:03:57 PM10/28/23
to sage-support
On Saturday, 28 October 2023 at 10:22:15 UTC-7 G. M.-S. wrote:

Thanks, Nils.

My question was motivated by using SageMath in my teachings.

Do you think it would be difficult/worthwhile taking care of this?
I mean, ideals in euclidean rings (or at least in ZZ).

Mathematically or algorithmically not difficult of course. I'd expect that to make it play nice with the category framework you'll need to do a lot of work. By the looks of ZZ.categories(), there is a category of "euclidean domains". The parent of ideals in ZZ, however, looks rather generic. I don't think the euclidean properties are propagated to the monoid of ideals at all at the moment. The "appropriate" level of generality would be there. However, there's not much to be gained from ideals in euclidean domains: we already have lcm and gcd! So I suspect that's why it's not implemented at the moment.

I can see how having such ideals may seem instructive for teaching. I think that's a matter of philosophy / opinion. I happen to not believe that teaching students formalisms in computer algebra packages without real benefit/content (beyond lcm and gcd that they'll learn anyway) helps them much, so I wouldn't think it's worthwhile. Perhaps for having facilities for ideals universally available, it could be useful if ideals in ZZ have "intersection" implemented, but I have trouble seeing where that would come up.

There are rings with ZZ as a subring for which intersection works on ideals proper, since we have groebner bases over ZZ, apparently:

sage: R.<x,y>=ZZ['x','y']
sage: I=R.ideal(15)
sage: J=R.ideal(35)
sage: I.intersection(J)

So you could use that ... or if you manage to define a multivariate polynomial ring over ZZ in 0 variables, you'd be good to go too. Free ZZ-modules of rank 1 would also get you the right behaviour.

G. M.-S.

unread,
Oct 29, 2023, 7:26:55 AM10/29/23
to sage-s...@googlegroups.com

Nils,

Thank you again for your explanations and insights, with which I agree.

As confirmed by the intersection methods you mention, I was thinking about consistency.

I try to make my students grasp the concepts of integral domains, GCD domains, UFDs, PIDs, Euclidean domains and fields.
One tool might be using SageMath to experiment with examples, but of course it will not replace doing mathematics.
If I understand you correctly, SageMath is a bit loose at the moment about its categories.
That is not a problem:  not to trust a computer blindly is part of my teaching.

Guillermo

Nils Bruin

unread,
Oct 29, 2023, 4:31:43 PM10/29/23
to sage-support
On Monday, 30 October 2023 at 00:26:55 UTC+13 G. M.-S. wrote:
If I understand you correctly, SageMath is a bit loose at the moment about its categories.

That's not what I meant also not what is indicated by what I noticed: by the looks of it, sage does know about euclidean domains and has quite a bit of ED-specific functionality. It's just that no-one has bothered specializing the *ideals* of euclidean domains. The definition of a Euclidean domain doesn't really mention ideals and indeed the subsequent properties of its ideals are established by lemmas and propositions. Basically, no-one has bothered making sagemath aware of those theorems (or even put the infrastructure in place to teach it about those results). So, no evidence of looseness in its categories. Just a little uneducated.


G. M.-S.

unread,
Oct 30, 2023, 8:26:46 PM10/30/23
to sage-s...@googlegroups.com

Nils,

Thanks for your patience and sorry for my ignorance.

Guillermo
Reply all
Reply to author
Forward
0 new messages