On 12/11/2014 4:26 am, Nicolas M. Thiery wrote:
 
Is this close enough from what you would want?

    sage: F = CombinatorialFreeModule(QQ, [1,2,3])
    sage: G = CombinatorialFreeModule(QQ, [4,5,6])
    sage: phi = F.module_morphism(lambda i: G.monomial(i+3), codomain=G)
    sage: psi = G.module_morphism(lambda i: F.monomial(i-3), codomain=F)
    sage: phi.register_as_coercion()
    sage: psi.register_as_coercion()

    sage: F(G.an_element())
    2*B[1] + 2*B[2] + 3*B[3]
    sage: G(F.an_element())
    2*B[4] + 2*B[5] + 3*B[6]
    sage: F.an_element() + G.an_element()
    4*B[1] + 4*B[2] + 6*B[3]

 Hi Nicolas,

This is a good start but it is not enough: essentially the difference 
between what I want and what this does is the same as the difference 
between a vector space isomorphism and an A-module isomorphism. As you 
pointed out, there are limitations if these objects are algebras. The same 
limitations apply to modules because any interesting 
CombinatorialFreeModule will come equipped with endomorphisms, actions and 
other methods. I would like a mechanism for automatically transferring 
these methods to the new module by implicitly invoking the coercions above. 
These methods will be both module methods and module element methods and, 
more generally, algebra and algebra element methods.

I don't think this this should be hard to do within the existing framework, 
and the mechanism should be roughly what you have above. After all, this is 
easy enough to do by hand because if F has a nice method then

sage: G(F(G.an_element()).nice_method())

transfers the method to G. The trick is to find an efficient, and seamless, 
way of doing this. If F is the original CombinatorialFreeModule (with 
distinguished basis), then the simplest hack would be to make __getattr__ 
in the class for G call the methods of F whenever they are not defined. So 
something like:

def __getattr__(self, attr):
     try:
         return self(getattr(F(self), atttr))
     except AttributeError:
         pass
     raise AttributeError('{} has no attribute {}\n'.format(self,attr))

The disadvantage of this approach is that it does not respect 
tab-completion and documentation, so it's probably going to be better to 
play some inheritance tricks. 

In terms of interface, I'd like to set up something like this:

sage: G=F.new_basis([4,5,6],basis_to_new_basis=phi, new_basis_to_basis=psi
,...)

This should accept a subset of the CombinatorialFreeModule arguments (for 
example, basis_keys, prefix, ...), as well as coercions to other bases for 
the module. As I said I'll try and think more about this.

This would certainly be useful for me. Let me know if it is unlikely to be 
useful for others.
Andrew


        

-- 
You received this message because you are subscribed to the Google Groups 
"sage-combinat-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-combinat-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-combinat-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-combinat-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to