Opened 11 years ago

Closed 10 years ago

# Can't construct a rational fraction from a symbolic one.

Reported by: Owned by: hivert robertwb major sage-4.6 coercion Fraction Field, coercion burcin sage-4.6.alpha2 Robert Bradshaw Florent Hivert, Burcin Erocal N/A

### Description

Given a symbolic expression which is a rational fraction sage refuse to convert it to a element of the Field of rational fraction:

```hivert@boxen:~\$ sage
----------------------------------------------------------------------
| Sage Version 4.2.1, Release Date: 2009-11-14                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: fr = (1+x)/(1+x+x^2)
sage: Fld = FractionField(PolynomialRing(QQ,x))
sage: Fld(fr)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (1181, 0))

[...]

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

[...]

/usr/local/sage/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_ring.pyc in _element_constructor_(self, x, check, is_gen, construct, **kwds)
304                 x = x.numerator() * x.denominator().inverse_of_unit()
305             else:
--> 306                 raise TypeError, "denominator must be a unit"
307
308         elif isinstance(x, pari_gen):

TypeError: denominator must be a unit
```

It seems that it needs to convert is to a polynomial. Of course if one convert numerator and denominator separately everything is Ok:

```sage: Fld((1+x))/(1+x+x^2)
(x + 1)/(x^2 + x + 1)
```

I'm not sure about which component should be selected... Is it algebra, calculus or coercion...

Florent

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

• Status changed from new to needs_review

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

• Authors set to Robert Bradshaw
• Reviewers set to Florent Hivert
• Status changed from needs_review to positive_review

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

• Status changed from positive_review to needs_work
• Work issues set to needs rebase

rebased to 4.4.4

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

• Status changed from needs_work to needs_review

### comment:6 Changed 11 years ago by demosd235

• Status changed from needs_review to needs_work

William points out that `denominator is 1` will fail unless denominator is the Python int 1, and nothing else...

Is this really preferable to `denominator == 1`?

PS, Passes tests in `sage/rings/fraction_field_element.pyx`

### comment:7 Changed 10 years ago by robertwb

• Status changed from needs_work to needs_review

Actually, the "is 1" was intentional, as I wasn't thinking of taking that path if the user passed in a ring element (as opposed to the default value) and didn't want to make the default value None and handle it everywhere. In retrospect, I think it's fine for it to be equal to 1.

### comment:8 Changed 10 years ago by burcin

• Milestone set to sage-4.6
• Reviewers changed from Florent Hivert to Florent Hivert, Burcin Erocal
• Status changed from needs_review to positive_review
• Work issues needs rebase deleted

### comment:9 Changed 10 years ago by mpatel

• Merged in set to sage-4.6.alpha2
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.