-
-
Notifications
You must be signed in to change notification settings - Fork 698
Description
It inherits _add_ and _sub_ methods that make no sense in the coercion system. These methods are guaranteed by the coercion system to get elements of the parent, and are supposed to give elements as well:
sage: M = FiniteRankFreeModule(ZZ, 2, name='M')
sage: G = M.general_linear_group()
sage: T11 = M.tensor_module(1, 1)
sage: from sage.structure.coerce import CoercionModel
sage: cm = CoercionModel()
sage: cm.explain(G, G, operator.add)
Identical parents, arithmetic performed immediately.
Result lives in General linear group of the Rank-2 free module M over the Integer Ring
General linear group of the Rank-2 free module M over the Integer Ring
Also other operations inherited from the module are problematic because they are not type-stable. The result of operations is supposed to depend only on the parents of the operands, but:
sage: cm.explain(ZZ, G, operator.mul)
Action discovered.
Left Integer Multiplication by Integer Ring on General linear group of the Rank-2 free module M over the Integer Ring
Result lives in General linear group of the Rank-2 free module M over the Integer Ring
General linear group of the Rank-2 free module M over the Integer Ring
sage: a = G.an_element()
sage: 2 * a
Type-(1,1) tensor on the Rank-2 free module M over the Integer Ring
sage: -a
Automorphism of the Rank-2 free module M over the Integer Ring
sage: (-1)*a
Automorphism of the Rank-2 free module M over the Integer Ring
sage: 0 *a
Automorphism of the Rank-2 free module M over the Integer Ring
(Note in particular the scary last one...)
There is already a coercion map from FreeModuleLinearGroup, sending a FreeModuleAutomorphism to the underlying tensor:
sage: M = FiniteRankFreeModule(ZZ, 2, name='M')
sage: G = M.general_linear_group()
sage: T11 = M.tensor_module(1, 1)
sage: T11.coerce_map_from(G)
Coercion map:
From: General linear group of the Rank-2 free module M over the Integer Ring
To: Free module of type-(1,1) tensors on the Rank-2 free module M over the Integer Ring
sage: _.category()
Category of elements of Set of Morphisms from General linear group of the Rank-2 free module M over the Integer Ring to Free module of type-(1,1) tensors on the Rank-2 free module M over the Integer Ring in Category of sets
This coercion can handle all of the module operations if we let it.
In this ticket, we change the relationship of FreeModuleAutomorphism and FreeModuleTensor from "is-a" to "has-a".
Making this change will also allow us to simplify FreeModuleTensor._add_ and _sub_: Currently they go through self._fmodule.tensor_from_comp() when they really should use self._new_instance.
CC: @egourgoulhon @tscrim @mjungmath
Component: linear algebra
Issue created by migration from https://trac.sagemath.org/ticket/30245