Opened 11 years ago

Closed 11 years ago

# FieldElement.quo_rem broken

Reported by: Owned by: burcin burcin major sage-4.4.4 basic arithmetic sage-4.4.4.alpha0 Burcin Erocal John Cremona N/A

### Description

```sage: P.<n> = QQ[]
sage: F = P.fraction_field()
sage: P.one_element()//F.one_element()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

.../sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.__floordiv__ (sage/rings/polynomial/polynomial_element.c:14608)()

.../sage/structure/element.so in sage.structure.element.NamedBinopMethod.__call__ (sage/structure/element.c:22812)()

.../sage/structure/element.so in sage.structure.element.FieldElement.quo_rem (sage/structure/element.c:16670)()

...
AttributeError: 'sage.rings.fraction_field_element.FractionFieldElement' object has no attribute '_parent'
```

### comment:1 Changed 11 years ago by burcin

• Authors set to Burcin Erocal
• Status changed from new to needs_review

### comment:2 Changed 11 years ago by cremona

I'm worried by the fact that right._parent fails while parent(right) succeeds.

### comment:3 Changed 11 years ago by burcin

`_parent` is a cdef'd attribute. At the point this code is used, Cython doesn't know that `right` is an `Element`, so it generates code to look for a python attribute `_parent` which fails.

One solution would be to use a type cast by writing `(<Element>right)._parent`, but we'd have to handle python types like `int` manually before this. The function `parent()`, which in turn calls `sage.structure.parent.parent_c` is used exactly for this purpose.

Calling parent_c directly would be faster, but that is not exported in `sage/structure/parent.pxd`.

### comment:4 Changed 11 years ago by cremona

• Status changed from needs_review to positive_review

That makes sense.

Patch applies fine to 4.4.2.rc0 and tests in sage/structure and sage/rings/ pass. So, positive review.

### comment:5 Changed 11 years ago by mhansen

• Merged in set to sage-4.4.4.alpha0
• Resolution set to fixed
• Reviewers set to John Cremona
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.