Opened 5 years ago

# g_algebras don't work over fields with parameters.

Reported by: Owned by: mmarco AlexGhitza major sage-6.4 algebra q_algebras, plural burcin, SimonKing, malb N/A

### Description

We can create g_algebras over QQ, but not over QQ(s), for example:

```sage: F.<x,y>=FreeAlgebra(QQ)
sage: F.g_algebra({y*x:x*y})
Noncommutative Multivariate Polynomial Ring in x, y over Rational Field, nc-relations: {}
sage: S=QQ['t'].fraction_field()
sage: F.<x,y>=FreeAlgebra(S)
sage: F.g_algebra({y*x:x*y})
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-47-86bec682bf82> in <module>()
----> 1 F.g_algebra({y*x:x*y})

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/algebras/free_algebra.pyc in g_algebra(self, relations, names, order, check)
869                 dmat[v2_ind,v1_ind]=d_poly
870         from sage.rings.polynomial.plural import g_Algebra
--> 871         return g_Algebra(base_ring, cmat, dmat, names = names or self.variable_names(), order=order, check=check)
872
873 from sage.misc.cache import Cache

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/factory.so in sage.structure.factory.UniqueFactory.__call__ (sage/structure/factory.c:1157)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/polynomial/plural.so in sage.rings.polynomial.plural.G_AlgFactory.create_key_and_extra_args (sage/rings/polynomial/plural.cpp:4858)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/matrix/matrix0.so in sage.matrix.matrix0.Matrix.change_ring (sage/matrix/matrix0.c:8931)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/matrix/matrix_space.pyc in __call__(self, entries, coerce, copy, rows)
505             deprecation(13012, "'rows=True/False' parameter is deprecated!")
506             return self.matrix(entries, coerce, copy, rows)
--> 507         return self.matrix(entries, coerce, copy)
508
509     def change_ring(self, R):

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/matrix/matrix_space.pyc in matrix(self, x, coerce, copy, rows)
1376                 x = list_to_dict(x, m, n)
1377                 copy = False
-> 1378         return MC(self, x, copy=copy, coerce=coerce)
1379
1380     def matrix_space(self, nrows=None, ncols=None, sparse=False):

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/matrix/matrix_generic_dense.so in sage.matrix.matrix_generic_dense.Matrix_generic_dense.__init__ (sage/matrix/matrix_generic_dense.c:2764)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/polynomial/multi_polynomial_ring.pyc in __call__(self, x, check)
485             return MPolynomial_polydict(self, x)
486         else:
--> 487             c = self.base_ring()(x)
488             return MPolynomial_polydict(self, {self._zero_tuple:c})
489

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:8134)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3856)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3757)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/fraction_field.pyc in _element_constructor_(self, x, y, coerce)
491                 return self._element_class(self, x.numerator(), x.denominator())
492         return self._element_class(self, x, y,
--> 493                 coerce=coerce, reduce = self.is_exact())
494
495     def construction(self):

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/fraction_field_element.so in sage.rings.fraction_field_element.FractionFieldElement.__init__ (sage/rings/fraction_field_element.c:2539)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/fraction_field_element.so in sage.rings.fraction_field_element.FractionFieldElement.__init__ (sage/rings/fraction_field_element.c:2381)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:8134)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3856)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3757)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring.pyc in _element_constructor_(self, x, check, is_gen, construct, **kwds)
424             if x.type() != 't_POL':
425                 x = x.Polrev()
--> 426         return C(self, x, check, is_gen, construct=construct, **kwds)
427
428     def is_integral_domain(self, proof = True):

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_rational_flint.so in sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint.__init__ (sage/rings/polynomial/polynomial_rational_flint.cpp:6205)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:8134)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3856)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3757)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/rational.so in sage.rings.rational.Rational.__init__ (sage/rings/rational.c:6728)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/rational.so in sage.rings.rational.Rational.__set_value (sage/rings/rational.c:8028)()

TypeError: Unable to coerce 0 (<class 'sage.algebras.free_algebra_element.FreeAlgebra_generic_with_category.element_class'>) to Rational
```

It is not a problem with singular, since it supports these constructions, i guess there is some bug somewhere, but i am having a hard time trying to track it.

### comment:1 Changed 5 years ago by mmarco

Ok, i could investigate something. One problem was that the d_matrix was created in the free algebra, and at some point, it tried to convert it to the corresponding polynomial ring (which is what singular expects). For some reason, sage didn't know how to do it if the base ring is a fraction field. There is even a comment in the source code stating that the coercion doesn't work, and we have to use a workaround. This patch makes the wourkaround an bit more complicated, but now builds the matrix in the polynomial ring.

Although now we hit a new proble: apparently, the plural interface does not support this kind of rings:

```sage: S=FractionField(QQ['t'])
sage: F.<x,y>=FreeAlgebra(S)
sage: F.g_algebra({y*x:-x*y+1+y})
singular_ring_delete(ring*) called with NULL pointer.
File "/home/mmarco/sage-5.11.beta1/local/bin/sage-ipython", line 18, in <module>
app.start()
File "/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/IPython/frontend/terminal/ipapp.py", line 363, in start
self.shell.mainloop()
File "/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 467, in mainloop
self.interact(display_banner=display_banner)
File "/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 586, in interact
self.run_cell(source_raw, store_history=True)
File "/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2592, in run_cell
interactivity=interactivity)
File "/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2671, in run_ast_nodes
if self.run_code(code):
File "/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2721, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-11-ec881bbe4ed3>", line 1, in <module>
F.g_algebra({y*x:-x*y+Integer(1)+y})
File "/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/algebras/free_algebra.py", line 876, in g_algebra
order=order, check=check)
Exception KeyError: (The ring pointer 0x0,) in 'sage.libs.singular.ring.singular_ring_delete' ignored
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-ec881bbe4ed3> in <module>()
----> 1 F.g_algebra({y*x:-x*y+Integer(1)+y})

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/algebras/free_algebra.pyc in g_algebra(self, relations, names, order, check)
874         from sage.rings.polynomial.plural import g_Algebra
875         return g_Algebra(base_ring, cmat, dmat, names = names or self.variable_names(),
--> 876                          order=order, check=check)
877
878 from sage.misc.cache import Cache

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/factory.so in sage.structure.factory.UniqueFactory.__call__ (sage/structure/factory.c:1242)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/structure/factory.so in sage.structure.factory.UniqueFactory.get_object (sage/structure/factory.c:1435)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/polynomial/plural.so in sage.rings.polynomial.plural.G_AlgFactory.create_object (sage/rings/polynomial/plural.cpp:4450)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/rings/polynomial/plural.so in sage.rings.polynomial.plural.NCPolynomialRing_plural.__init__ (sage/rings/polynomial/plural.cpp:5300)()

/home/mmarco/sage-5.11.beta1/local/lib/python2.7/site-packages/sage/libs/singular/function.so in sage.libs.singular.function.SingularFunction.__call__ (sage/libs/singular/function.cpp:12438)()

TypeError: Cannot call Singular function 'nc_algebra' with ring parameter of type '<class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain_with_category'>'

```

### comment:2 Changed 4 years ago by vbraun_spam

• Cc changed from burcin, SimonKing, malb, to burcin, SimonKing, malb
• Milestone changed from sage-6.1 to sage-6.2

### comment:3 Changed 4 years ago by vbraun_spam

• Milestone changed from sage-6.2 to sage-6.3

### comment:4 Changed 4 years ago by vbraun_spam

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