"Conversions need not be canonical (they may for example involve a choice of lift) or even make sense mathematically (e.g. constructions of some kind)."
Anyone has a strong opinion about what we should let Sage do in such a situation?
Should we leave the old conversion when there is no coercion even though that might easily to wrong mathematical results for a careless user? Or never look for a coercion unless the user explicitly asks for it (i.e. what the situation is currently in Sage without the patches of the ticket)?
Best,
JP
Currently one can obtain surprising results in Sage when converting polynomial over finite fields (or elements of quotient rings of univariate polynomial ring even though tht's not the primary concern of the ticket).
See http://trac.sagemath.org/ticket/11239
Basically the generators of the finite fields are just exchanged, even when the characteristics are different.
The changes suggested in this ticket would more or less only let a coercion be used if there is one, and rant if the characteristics are different or the base finite fields are not part of a common lattice when there is no canonical embedding.
Note though that the original disturbing conversion fits with the current behavior described in the doc:
* http://www.sagemath.org/doc/reference/coercion/index.html#maps-between-parents
where it's stated that"Conversions need not be canonical (they may for example involve a choice of lift) or even make sense mathematically (e.g. constructions of some kind)."
Anyone has a strong opinion about what we should let Sage do in such a situation?
Should we leave the old conversion when there is no coercion even though that might easily to wrong mathematical results for a careless user? Or never look for a coercion unless the user explicitly asks for it (i.e. what the situation is currently in Sage without the patches of the ticket)?
Warning: I am partially playing "advocatus diavoli" here.
> so let me just say here that I think this
> principle (that conversions need not be canonical) shouldn't be pushed
> further than reasonable.
Yes, but for a rather relaxed notion of "reasonable". For example, you
couldn't even say that you have a "conversion from K[x]/(f) to
K[x]/(g)", since a conversion is not a map. It is a *partial* map,
hence, it often is the case that only polynomials of degree zero can be
converted and higher degree polynomials result in an error.
> For example, if K is a field and f, g in K[x] are
> polynomials, then applying a conversion K[x]/(f) -> K[x]/(g) is a sensible
> thing to do if g divides f (the canonical map) or if f divides g (the
> lifting map). However, I don't see why it is important to insist that the
> composition of two such maps (e.g. K[x]/(f) -> K[x] -> K[x]/(g) when f, g
> have nothing to do with each other) should again be a valid conversion that
> can be invoked with the same ease.
Hang on. Nobody says that the composition of two conversions A->B and
B->C yields a conversion A->C (even if we forget for the moment that
conversions are not more than partially defined maps)! Composibility
is an axiom for *coercions*, but not for *conversions*. Actially conversion
have no axioms worth mentioning.
Hence, it would be perfectly fine to have K[x]/(f)->K[x] and
K[x]->K[x]/(g) for *all* elements of the involved rings, but
no conversion from K[x]/(f)->K[x]/(g), or actually: Only conversion for
polynomials of degree zero.
That said, do you really think one should do more or less expensive
operations (such as: compute gcd or a prime factorisation) to
verify that an easy conversion rule makes sense in a particular case?
You say it should not be pushed further than reasonable. Is it reasonable
to have an expensive test to decide whether or not to apply an easy
conversion rule? Recall: Coercions should obey axioms and thus expensive
tests may be needed. But why should one have expensive tests for something
that has no defined properties? How *could* you possibly test something
that has no defined properties?
> Hence I think that R(h), for R =
> K[x]/(g) and h in L[x]/(f), should only be allowed when K has a canonical
> map to L and either f divides g (in L[x]) or vice versa.
Do you claim we should drop conversion entirely? After all, we also have a
*coercion* system, and coercions (as opposed to conversions) are supposed to
be mathematically consistent. Do you think this would be reasonable?
If there is a coercion map then conversion must give the same result.
Everything else would be a bug.
I sometimes illustrate techniques of polynomial factorization in a class by starting with a polynomial in ZZ[x] and converting it to a polynomial in GF(insert_large_prime)[x]. I realize this is not an instance of two _finite_ fields, but (a) you mention "the characteristics are different", and (b) _are_ there similar applications for finite fields, when the characteristics are different?
What I don't like is this:
sage: GF(7)(ZZ(GF(11)(7)))
0
where the convenient lifting function from GF(p) to ZZ is done
automatically instead of via the functions lift() and centerlift()
A conversion map is (by definition) a partial map, that in some cases
happens to be an actual map (not just partial), in other cases happens
to even be a morphism, and in the best case is a coerce map.
I'd say this is (close to) a bug.
So, we should think of being more precise, introduce "Set of partial maps from
R to S", and use it as parents of partial maps that aren't maps.
Similarly, one should more consistently distinguish between the set of
all maps and the set of all morphisms.
I would like to add that in my opinion the first line of this example,
sage: f = GF(11).convert_map_from(GF(7))
should not be assumed to work at all, and it would be preferable to raise an error rather than returning something that is mathematically completely arbitrary.
Given how few properties a "conversion map" is actually guaranteed to have, wouldn't it be sufficient to just have a callable represent the conversion and not demand it's a map?
I don't think we really need domain and codomain anyway. It also means that in a lot of cases, one could simply store to codomain rather than a map wrapping a call to the codomain.
Except that currently (if A is the codomain) A.__call__() looks for a conversion and calls it, where the default conversion consists of calling A._element_constructor_(), so just letting the conversion f be the callable A itself instead would create a circularity (A(x) = A.__call__(x) = f(x) = A(x) = ...). To implement your proposal, one could return "lambda x: return A._element_constructor_(x)" as the conversion.
Hi Simon,
I'd say this is (close to) a bug.
It is a bug, without qualification.
So, we should think of being more precise, introduce "Set of partial maps from
R to S", and use it as parents of partial maps that aren't maps.
Similarly, one should more consistently distinguish between the set of
all maps and the set of all morphisms.
That seems to be the only reasonable solution.
I would like to add that in my opinion the first line of this example,
sage: f = GF(11).convert_map_from(GF(7))
should not be assumed to work at all, and it would be preferable to raise an error rather than returning something that is mathematically completely arbitrary.
Given the principle that no conditions are imposed on conversions (except that if a coercion exists, the conversion equals the coercion), it should in particular be perfectly fine if some of them do not satisfy the property of existing at all.
Peter