Opened 14 months ago

# is_unit() gives incorrect result for quotient of number ring

Reported by: Owned by: gh-mathehertogh minor sage-9.7 number fields N/A

### Description

Consider the following example:

```sage: version()
'SageMath version 9.3.beta6, Release Date: 2021-01-17'
sage: K.<a> = NumberField(x^3-2)
sage: O = K.maximal_order()
sage: I = O.ideal(4)
sage: Omod4 = O.quotient(I, 'b')
sage: a + I == 1 # Are a and 4 coprime? (no)
False
sage: a_bar = Omod4(a)
sage: a_bar.is_unit() # So this should return False...
True
sage: a_bar.parent()
Quotient of Maximal Order in Number Field in a with defining polynomial x^3 - 2 by the ideal (4)
```

Clearly the method `is_unit()` gives the wrong answer in this example.

I checked the implementation:

```sage: a_bar.is_unit??
...
def is_unit(self):
"""
Return True if self is a unit in the quotient ring.
...
"""
if self.__rep.is_unit():
return True
from sage.categories.fields import Fields
if self.parent() in Fields:
return not self.is_zero()
try:
self.__invert__()
return True
except ArithmeticError:
return False
raise NotImplementedError
```

When I trace through this, I do not understand what happens. On the first line `self.__rep.is_unit()` returns `True`, while my debugger says `self` has no attribute `__rep`. When I step into this call, I end up in `K.is_field()`, which returns `True`.

I tried checking if for some reason we where executing the line `if self.parent() in Fields`, but this does not seem to be the case: `self.parent()` gives `Quotient of Maximal Order in Number Field in a with defining polynomial x^3 - 2 by the ideal (4)`

### comment:1 Changed 14 months ago by gh-DaveWitteMorris

`self.__rep` is another name for `self.lift()`, which is equal to `a`.

The lift is erroneously being considered as an element of the field `K`, instead of as an element of the order `O`.

```sage: a_bar.lift().parent()
Number Field in a with defining polynomial x^3 - 2
sage: Omod4(2).lift().parent()
Number Field in a with defining polynomial x^3 - 2
sage: Omod4(2).is_unit()
True
```

Possibly related tickets: #12242 and #28552.

### comment:2 Changed 12 months ago by mkoeppe

• Milestone changed from sage-9.3 to sage-9.4

Moving to 9.4, as 9.3 has been released.

### comment:3 Changed 9 months ago by mkoeppe

• Milestone changed from sage-9.4 to sage-9.5

### comment:4 Changed 5 months ago by mkoeppe

• Milestone changed from sage-9.5 to sage-9.6

### comment:5 Changed 2 weeks ago by mkoeppe

• Milestone changed from sage-9.6 to sage-9.7
Note: See TracTickets for help on using tickets.