Is this a bug in multipoly _div_?

28 views
Skip to first unread message

Ben Hutz

unread,
Nov 12, 2012, 12:06:29 PM11/12/12
to sage-...@googlegroups.com
The following works

sage: R.<t>=PolynomialRing(QQ)
sage: S.<x>=PolynomialRing(R)
sage: x/S(2)
x/2

The following does not

sage: R.<t>=PolynomialRing(QQ)
sage: S.<x,y>=PolynomialRing(R)
sage: x/S(2)            
Traceback (most recent call last):
...
AttributeError: 'int' object has no attribute 'parent'

Seems to me that if the first one works, then so should the second. I searched the trac server and couldn't come up with anything on this.

Thanks,
  Ben

Volker Braun

unread,
Nov 12, 2012, 12:51:43 PM11/12/12
to sage-...@googlegroups.com
This is yet another inconsistency with multivariate vs. univariate polynomial rings. They are implemented differently, so its easy to fall into these traps. I don't have any better idea than hope that it gets ironed out over time...

P Purkayastha

unread,
Nov 12, 2012, 1:07:20 PM11/12/12
to sage-...@googlegroups.com
There is a simple fix for this (I hope).


--- a/sage/rings/polynomial/multi_polynomial_element.py
+++ b/sage/rings/polynomial/multi_polynomial_element.py
@@ -280,7 +280,7 @@
53 bits of precision
"""
if right in self.base_ring():
- inv = 1/self.base_ring()(right)
+ inv = self.base_ring()(1)/self.base_ring()(right)
return inv*self
return self.parent().fraction_field()(self, right, coerce=False)


If it looks right, then I can try and open a ticket.


P Purkayastha

unread,
Nov 12, 2012, 1:08:18 PM11/12/12
to sage-...@googlegroups.com
Oh. by the way, the command works after applying this ppatch:

sage: sage: R.<t>=PolynomialRing(QQ)
sage: sage: S.<x,y>=PolynomialRing(R)
sage: sage: x/S(2)
1/2*x


Ben Hutz

unread,
Nov 12, 2012, 2:43:16 PM11/12/12
to sage-...@googlegroups.com
That seems like it fixes the symptoms, but I'm not sure if it is the source of the problem. For example, the following already works without the fix.

sage: R.<s,t>=PolynomialRing(QQ)
sage: S.<x,y>=PolynomialRing(R)
sage: x/S(2)
1/2*x

That being said, I wasn't able to come up with an example that breaks with your change. So with a change this innocuous, I'll review it as a fix of this particular problem.

Nils Bruin

unread,
Nov 12, 2012, 3:48:48 PM11/12/12
to sage-devel
On Nov 12, 10:07 am, P Purkayastha <ppu...@gmail.com> wrote:

> +            inv = self.base_ring()(1)/self.base_ring()(right)

It's probably more efficient to do:

inv = self.base_ring().one()/self.base_ring()(right)

since it completely avoids the coercion framework for constructing 1.

P Purkayastha

unread,
Nov 12, 2012, 8:33:39 PM11/12/12
to sage-...@googlegroups.com
Thanks. I have opened #13704 with this change.

http://trac.sagemath.org/13704

Reply all
Reply to author
Forward
0 new messages