[Not sure if this belongs here or in sage-dev...]
I am trying to implement coercions between algebras that are related by base change. For example,consider
A=CombinatorialFreeModule(ZZ['x'], ['1','2'])
B=CombinatorialFreeModule(ZZ, ['1','2'])
A.module_morphism(
lambda a: B._from_dict({b: c.subtitute(x=1) for (b,c) in a}),
codomain=B, category=A.category()
).register_as_coercion()
This fails with a category mismatch error because A is defined over Z[x] and B over Z:
ValueError: Free module generated by {'1', '2'} over Univariate Polynomial Ring in x over Integer Ring is not in Category of finite dimensional modules with basis over Integer Ring
This is entirely reasonable because I have not specified how Z is a Z[x]-module, but when I try to define this it seems I need slightly different syntax:
Rx = ZZ['x]
R = ZZ
Rx.module_morphism(function=lambda f: f.substitute(x=1), codomain=R)
This also fails with a category mismatch:
ValueError: Integer Ring is not in Category of modules over Integer Ring
My actual use case is slightly more complicated in that I have an algebra defined as a combinatorial free module with multiple realisations and the rings could be different, but this is the essence of my problem. I could just fudge this but I'd like to do this "properly".
Andrew