ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 14 Dec 2010 03:29:42 -0600How to add term order to free module?http://ask.sagemath.org/question/7809/how-to-add-term-order-to-free-module/I am working with a free module over a ring of polynomials, and need more than what's available in FreeModule. To be specific, I want to define an order on the terms in the module (think term orders for Grobner bases), and then to be able to obtain leading monomials of module elements.
I tried to augment sage.modules.free_module_element.FreeModuleElement.__bases__ with my own mix-in as described in the tutorial, but apparently FreeModuleElement cannot be augmented in this way.
Presumably I could also put together derived classes for FreeModule and FreeModuleElement, but I'm somewhat up in the air as how to do this.
I considered augmenting my ring of polynomials with extra variables as a back-door way to produce my free module, but the term orders available in polynomial rings are not general enough for my application.
Any suggestions? So far I have worked around the problem, but it's ugly.Sun, 12 Dec 2010 11:51:06 -0600http://ask.sagemath.org/question/7809/how-to-add-term-order-to-free-module/Comment by John Palmieri for <p>I am working with a free module over a ring of polynomials, and need more than what's available in FreeModule. To be specific, I want to define an order on the terms in the module (think term orders for Grobner bases), and then to be able to obtain leading monomials of module elements.</p>
<p>I tried to augment sage.modules.free_module_element.FreeModuleElement.__bases__ with my own mix-in as described in the tutorial, but apparently FreeModuleElement cannot be augmented in this way.</p>
<p>Presumably I could also put together derived classes for FreeModule and FreeModuleElement, but I'm somewhat up in the air as how to do this.</p>
<p>I considered augmenting my ring of polynomials with extra variables as a back-door way to produce my free module, but the term orders available in polynomial rings are not general enough for my application.</p>
<p>Any suggestions? So far I have worked around the problem, but it's ugly.</p>
http://ask.sagemath.org/question/7809/how-to-add-term-order-to-free-module/?comment=22419#post-id-22419Have you tried "CombinatorialFreeModule" instead of "FreeModule"? For giving elements names, for example, it's very good, and it might suit your needs.Sun, 12 Dec 2010 14:59:33 -0600http://ask.sagemath.org/question/7809/how-to-add-term-order-to-free-module/?comment=22419#post-id-22419Answer by Jason Bandlow for <p>I am working with a free module over a ring of polynomials, and need more than what's available in FreeModule. To be specific, I want to define an order on the terms in the module (think term orders for Grobner bases), and then to be able to obtain leading monomials of module elements.</p>
<p>I tried to augment sage.modules.free_module_element.FreeModuleElement.__bases__ with my own mix-in as described in the tutorial, but apparently FreeModuleElement cannot be augmented in this way.</p>
<p>Presumably I could also put together derived classes for FreeModule and FreeModuleElement, but I'm somewhat up in the air as how to do this.</p>
<p>I considered augmenting my ring of polynomials with extra variables as a back-door way to produce my free module, but the term orders available in polynomial rings are not general enough for my application.</p>
<p>Any suggestions? So far I have worked around the problem, but it's ugly.</p>
http://ask.sagemath.org/question/7809/how-to-add-term-order-to-free-module/?answer=11858#post-id-11858To slightly elaborate on John's comment, "CombinatorialFreeModule" allows you to specify an arbitrary comparison function on the elements. Here is a sample doctest from sage.categories.modules_with_basis :
sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X")
sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3)
sage: x.leading_monomial()
B[3]
sage: def cmp(x,y): return y-x
sage: x.leading_monomial(cmp=cmp)
B[1]
Tue, 14 Dec 2010 03:29:42 -0600http://ask.sagemath.org/question/7809/how-to-add-term-order-to-free-module/?answer=11858#post-id-11858