On 17 February 2017 at 12:26, Clemens Heuberger
<clemens.heuber...@aau.at> wrote:
>
> The situation is as follows:
>
> sage: R.<a, b> = ZZ[]
> sage: (2*a/b).factor()
> 2 * b^-1 * a
> sage: (a/(2*b)).factor()
> 2^-1 * b^-1 * a
> sage: (3*a/(2*b)).factor()
> Traceback (most recent call last):
> ...
> TypeError: Cannot multiply 3 * a and 2^-1 * b^-1 because they cannot be 
> coerced
> into a common universe
>
> However, the univariate ring behaves differently:
>
> sage: S.<c> = ZZ[]
> sage: (2*c/(c+1)).factor()
> 2 * (c + 1)^-1 * c
> sage: (c/(2*(c+1))).factor()
> 2^-1 * (c + 1)^-1 * c
> sage: (3*c/(2*(c+1))).factor()
> 2^-1 * 3 * (c + 1)^-1 * c
>
>
> Am 2017-02-16 um 17:11 schrieb John Cremona:
>> On 16 February 2017 at 15:07, Clemens Heuberger
>> I would say that was a bug.  Change ZZ to QQ and it is fine.
>
> I still consider the current behaviour to be a bug, especially in view of the
> better behaviour of the univariate ring. In particular, throwing a TypeError
> seems to be quite inappropriate here.
>
> I usually prefer to work in the fraction field of ZZ[] because the results 
> tend
> to be nicer (and I am not particularly happy to convert my final result just 
> to
> get some copy&paste ready version).

I agree.  Here, I think it is a rather simple thing caused by a lack
of flexibility in the Factorization class:

sage: R.<a, b> = ZZ[]sage: h = f*g
sage: h.numerator().parent()
Multivariate Polynomial Ring in a, b over Integer Ring

sage: f = 3*a
sage: g = 1/(2*b)
sage: f.parent()
Multivariate Polynomial Ring in a, b over Integer Ring
sage: g.parent()
Fraction Field of Multivariate Polynomial Ring in a, b over Integer Ring
# no problem here:
sage: f*g
3*a/(2*b)
# but

sage: h = f*g
sage: h.numerator().parent()
Multivariate Polynomial Ring in a, b over Integer Ring
sage: h.denominator().parent()
Multivariate Polynomial Ring in a, b over Integer Ring

sage: hnf = h.numerator().factor(); hnf
3 * a
sage: hdf = h.denominator().factor(); hdf
2 * b
sage: hnf/hdf
<boom>
sage: hdfinv = hdf**-1; hdfinv
2^-1 * b^-1

Now when the two factorizations hnf and hdfinv are multiplied it tries
to cperce both in to the same universe, which should R, it it takes
the universe from the first item in each factorization, which are the
integers 3 and 2, so it incorrectly defined the universe to be ZZ,
(THis is in the __mul__() method of the Factorization class) and then
fails (of course) to coerce the other irreducibles into that universe.

This arises because (taking the numerator, the same being true for the
denominator) the factorization of 3*a is
sage: list(hnf)
[(3, 1), (a, 1)]
sage: [p[0].parent() for p in hnf]
[Integer Ring, Multivariate Polynomial Ring in a, b over Integer Ring]

The fault lies (in my opinion) in the function which factors elements
of R, which deals wrongly with integer factors, leaving them as
elements of ZZ instead of as constant elements of R.

I think this diagnoses the problem and points to where the fix is, but
someone else will have to make that fix.

John

>
>
> --
> 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 post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to