Below is a response that I began. The issues raised here made me
realise that I didn't and don't understand what the coercion model
is supposed to model. Is there an article available which sets
out the definitions, problems or issues, and solution provided
by the coercion model? Such a document would be helpful to avoid
reinventing for each category what the model is supposed to do and
ending up with incoherent decisions, based on what seems natural
in individual contexts. The "correct" behavior, even if at first
counterintuitive, should be determined by general principles.
I'll send the rest of the (incomplete) message as is.
Best,
David
> Problem: Free modules are currently not using the coercion model
> properly. For example, they do not define _coerce_map_from_.
>
> Question 1:
> Submodules do not define their embedding into the ambient module as
> coercion.
> sage: M = FreeModule(ZZ,3,inner_product_matrix=Matrix(3,3,range(9)))
> sage: S = M.submodule([M.random_element(),M.random_element()])
> sage: S.coerce_embedding() is None
> True
>
> Should this be changed?
Sure.
> Question 2:
> When should there be a coercion from free (abstract, non-embedded)
> modules M to N?
Clearly when:
M is N
M is created as a free submodule of N (as above), extended
to the lattice of submodules of some fixed ambient module.
N is created as a quotient of M (probably not implemented
in such a way that this can be determined).
> Certainly we need coercion from M.base_ring() to N.base_ring() and M.
> Also, we need M.rank()==N.rank() and M.degree()==N.degree().
This would effectively identify all free modules of the same rank
and degree. I would have a better understanding of the idea of
the coercion model (and where it is applied) to know whether
isomorphic-but-not-canonically-isomorphic objects are supposed
to have a coercion between them. This is analogous to the question
about distinct but isomorphic number fields with or without the
same defining polynomials (with the same polynomials they are
computationally, but not necessarily canonically isomorphic).
> In the other thread, it seemed to be agreement that, if N has an inner
> product matrix defined by the user (this can be tested with
> is_FreeQuadraticModule), then a coercion from M to N requires that M
> has the same inner product matrix (either by default or user-defined).
> If N has no explicit inner product, then we may have the forgetful
> coercion from M to N.
Comment (*):
This is essentially a question of different categories -- if the
category of the free module is that of inner product spaces, then
there are fewer (homo)morphisms. But I don't know if the coercion
model adopts such a strong categorical hierarchy. It seems to mix
canonical homomorphisms in a category with functors between categories.
> Question 2a):
> Apparently there is a sparse and a dense implementation of free
> modules. Should a coercion be allowed in both directions? Only from
> sparse to dense (it seems that dense is default)? Only from dense to
> sparse?
This concerns implementation or performance issues of writing out
sparse matrices as dense ones or expressing a dense matrix in a
form in which it would be more expensive. But both coercions seem
important to easily convert between types.
> Question 2b):
> What about sub-modules? I guess we don't want coercion from an
> abstract free module into a sub-module. Presumably a sub-module M (of
> an ambient module A) coerces into a sub_module N (of an ambient module
> B) if and only if there is coercion from A to B that sends M to a
> subset of N.
>
> Question 3:
> I guess it is straight forward that pushout(A,B) of two sub-modules A
> of M and B of N (hence, the structure in which arithmetic between
> elements of A and B is performed) will be the submodule of
> pushout(M,N) that is generated by the images of A and B. Agreed?
My comment (*) makes it clear (to me) that I don't know what the
coercion model is supposed to model (functors or homomorphisms).