Skip to content

Zero does not belong to zero ideal of a number field #14366

@sagetrac-olitb

Description

@sagetrac-olitb

The following is mathematically wrong:

sage: 0 in CyclotomicField(3).ideal(0)
False

It comes from the function contains(self, x) in the class NumberFieldIdeal (file sage/rings/number_field/number_field_ideal.py), which tries to compute the coordinates of the element in a basis (over ZZ) of the ideal. The function coordinates(self, x) fails for the zero ideal, raising a TypeError (in fact when _contains_ is called directly, a TypeError is raised).
A workaround is to replace

def _contains_(self, x):
    return self.coordinates(self.number_field()(x)).denominator() == 1

with

def _contains_(self, x):
    return x==0 or self.coordinates(self.number_field()(x)).denominator() == 1

but I am not sure if it is the "right" way to do it.
Is it desirable to have the _contains_ function in sage/rings/ideal.py catch the TypeError (silently)?

Apply attachment: 14366_metrod3.patch​

Component: number fields

Keywords: sd51

Author: Michiel Kosters

Reviewer: David Loeffler

Merged: sage-5.12.beta3

Issue created by migration from https://trac.sagemath.org/ticket/14366

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions