Thanks Nils. Actually, I think that what I need is a conversion rather than a coercion as `register_as_conversion()` lets me change the category.
On Wednesday 31 July 2024 at 2:49:16 am UTC+10 Nils Bruin wrote: > On Monday 29 July 2024 at 22:13:27 UTC-7 Andrew wrote: > > [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() > > > Are you sure you want to register that as a *coercion*? Those are to be > used in other coercion discoveries as well and can be used implicitly to > resolve things like a+b, where a in A and b in B (and extensions of these!) > > > 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) > > > These are bases, so I think you should define a ring homomorphism between > them (I think a CombinatorialFreeModule has a ring as its base). And then > you see how you'd get a problem if you insert a coercion from ZZ['x'] to > ZZ: there's already one in the oppositie direction and sage really prefers > its coercion graph to not have directed cycles. > > So I expect that your original map A -> B should really be one from a > ZZ['x']-module to a ZZ-module, where ZZ is really ZZ['x']/(x-1). > > In fact, with > > P.<x>=ZZ[] > R=P.quo(x-1) > A=CombinatorialFreeModule(P, ['1','2']) > B=CombinatorialFreeModule(R, ['1','2']) > > I get: > > sage: x*A('1')+B('2') > B['1'] + B['2'] > > so it seems to discover the coercion correctly. (I do get that A('1') > prints as B['1'] so there is something fishy there. Are combinatorial > modules always printing as `B`? or is that the default name for its > "basis"?) > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/740ab93d-22ae-45b0-b2b9-37ddc9f38b79n%40googlegroups.com.