Opened 5 years ago

Last modified 5 years ago

#19388 new enhancement

Write better doctest for parent.register_embedding

Reported by: nbruin Owned by:
Priority: minor Milestone: sage-6.9
Component: misc Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

One of the current doctests on parent.register_embedding doesn't actually do what it should:

           sage: x = QQ['x'].0
            sage: t = abs(ZZ.random_element(10^6))
            sage: K = NumberField(x^2 + 2*3*7*11, "a"+str(t))
            sage: a = K.gen()
            sage: K_into_MS = K.hom([a.matrix()])
            sage: K._unset_coercions_used()
            sage: K.register_embedding(K_into_MS)
            sage: L = NumberField(x^2 + 2*3*7*11*19*31, "b"+str(abs(ZZ.random_element(10^6))))
            sage: b = L.gen()
            sage: L_into_MS = L.hom([b.matrix()])
            sage: L._unset_coercions_used()
            sage: L.register_embedding(L_into_MS)
            sage: a * b.matrix()
            [this shouldn't test a registered embedding at all]

The problem here is that there is an "action" defined of K on parent(b.matrix()) (namely, scalar multiplication on the base changed matrix) and actions are supposed to be discovered before coercions are, as documented on, e.g. get_coercion_model().bin_op. Previously, action discovery failed with an embedding map that produces unhashable elements, so the test above would use the registered embedding due to a covered up unexpected error. So the test only accidentally had anything to do with the registered embedding. With #19016 this is no longer the case. Can we replace this test with something more sensible? (also, note that anything calling _unset_coercions_used is a hack).

Change History (1)

comment:1 Changed 5 years ago by nbruin

  • Priority changed from major to minor

One possible fix:

M = MatrixSpace(QQ,2,2)
Kt.<at> = NumberField(x^2+2)
K.<a> = NumberField( at.minpoly(), embedding=at.matrix())
Lt.<bt> = NumberField(x^2+3)
L.<b> = NumberField( bt.minpoly(), embedding=bt.matrix())
M.coerce_map_from(K)(a)*M.coerce_map_from(L)(b)

The last should really be spelled M(a)*M(b) but that currently doesn't work (coercions should always be valid conversions too, and M(a) should try conversion).

Note: See TracTickets for help on using tickets.