The inheritance from FieldElement has caused problems for a long time, and 
I would welcome a fix. (See issue #12242 
<https://github.com/sagemath/sage/issues/12242> from 2011 for example.)  
Please open an issue.  It seems to me that the relation between OK and K 
should be similar to the relation between ZZ and QQ, so there shouldn't be 
any need for elements of OK to inherit from FieldElement.

On Sunday, April 27, 2025 at 11:06:03 PM UTC-4 Nils Bruin wrote:

> I ran into the following problem for elements of rings of integers: they 
> inherit from FieldElement. That's a problem when, for instance you want to 
> implement a method "canonical_associate" that tries to find a canonical 
> representative modulo multiplication by units. For fields, such a thing is 
> easily defined, but for rings of integers such a method isn't necessarily 
> easy to implement. It's natural to implement this method on "FieldElement", 
> but then elements of rings of integers inherit that method (and it does the 
> wrong thing there!)
>
> I'd be interested if someone has a coherent idea about how we can handle 
> such issues. It seems to me we have a problem in our inheritance hierarchy. 
> I suspect someone made this design decision (that superficially looks like 
> an error) for a good reason and may have put some thought into how to 
> easily work around the obvious draw-backs.
>
> The following mro illustrates the problem:
>
> sage: R.<x>=ZZ[]
> sage: K.<a>=NumberField(x^3+x+1)
> sage: OK=K.ring_of_integers()
> sage: type(OK.0).mro()
> [<class 
> 'sage.rings.number_field.number_field_element.OrderElement_absolute'>,
>  <class 
> 'sage.rings.number_field.number_field_element.NumberFieldElement_absolute'>,
>  <class 'sage.rings.number_field.number_field_element.NumberFieldElement'>,
>  <class 
> 'sage.rings.number_field.number_field_element_base.NumberFieldElement_base'>,
>  <class 'sage.structure.element.FieldElement'>,
>  <class 'sage.structure.element.CommutativeRingElement'>,
>  <class 'sage.structure.element.RingElement'>,
>  <class 'sage.structure.element.ModuleElement'>,
>  <class 'sage.structure.element.Element'>,
>  <class 'sage.structure.sage_object.SageObject'>,
>  <class 'object'>]
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/sage-devel/952c6377-5cb9-494d-a9fe-4924b569a55an%40googlegroups.com.

Reply via email to