Open nthiery opened 10 years ago
Description changed:
---
+++
@@ -13,14 +13,13 @@
Vector space morphism represented by the matrix:
[2 2]
[2 2]
+Domain: Vector space of dimension 2 over Finite Field of size 7
+Codomain: Vector space of dimension 2 over Finite Field of size 7
So far, so good. But:
-
-Domain: Vector space of dimension 2 over Finite Field of size 7
-Codomain: Vector space of dimension 2 over Finite Field of size 7
sage: K(2)*phi
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
@@ -33,3 +32,11 @@
TypeError: unsupported operand parent(s) for '*': 'Finite Field of size 7' and 'Set of Morphisms (Linear Transformations) from Vector space of dimension 2 over Finite Field of size 7 to Vector space of dimension 2 over Finite Field of size 7'
+
+In particular this prevents illustrating Cayley-Hamilton on the morphism side:
+
+ +sage: phi.characteristic_polynomial()(phi) +... +TypeError: unsupported operand parent(s) for '*': 'Finite Field of size 7' and 'Set of Morphisms (Linear Transformations) from Vector space of dimension 2 over Finite Field of size 7 to Vector space of dimension 2 over Finite Field of size 7' +
That looks like the category machinery is not cooperating with coercion properly. The scalar multiplication should be there according to the categories:
sage: parent(phi).categories()
[Category of hom sets in Category of modules over Finite Field of size 7,
Category of vector spaces over Finite Field of size 7,
Category of modules over Finite Field of size 7,
Category of bimodules over Finite Field of size 7 on the left and Finite Field of size 7 on the right,
Category of right modules over Finite Field of size 7,
Category of left modules over Finite Field of size 7,
Category of commutative additive groups,
Category of additive groups,
Category of additive inverse additive unital additive magmas,
Category of commutative additive monoids,
Category of additive monoids,
Category of additive unital additive magmas,
Category of commutative additive semigroups,
Category of additive commutative additive magmas,
Category of additive semigroups,
Category of additive magmas,
Category of hom sets in Category of sets,
Category of hom sets in Category of sets with partial maps,
Category of hom sets in Category of objects,
Category of sets,
Category of sets with partial maps,
Category of objects]
By the way, going up the inheritance in the code:
sage: sage.modules.vector_space_homspace.VectorSpaceHomspace.mro()
[sage.modules.vector_space_homspace.VectorSpaceHomspace,
sage.modules.free_module_homspace.FreeModuleHomspace,
sage.categories.homset.HomsetWithBase,
sage.categories.homset.Homset,
sage.structure.parent.Set_generic,
sage.structure.parent.Parent,
sage.structure.category_object.CategoryObject,
sage.structure.sage_object.SageObject,
object]
and reading the code, it's completely unclear how parent(phi)
got those module categories attached to it. It would have to happen somewhere in sage.modules.vector_space_homspace.VectorSpaceHomspace, sage.modules.free_module_homspace.FreeModuleHomspace
but none of those classes have an __init__
.
Replying to @nbruin:
That looks like the category machinery is not cooperating with coercion properly. The scalar multiplication should be there according to the categories:
Well, categories are doing nothing here but stating the math. This issue is really about the concrete class VectorSpaceMorphism for morphisms defined by a matrix which is responsible for implementing multiplication by scalars, and apparently does not.
By the way, going up the inheritance in the code:
sage: sage.modules.vector_space_homspace.VectorSpaceHomspace.mro() [sage.modules.vector_space_homspace.VectorSpaceHomspace, sage.modules.free_module_homspace.FreeModuleHomspace, sage.categories.homset.HomsetWithBase, sage.categories.homset.Homset, sage.structure.parent.Set_generic, sage.structure.parent.Parent, sage.structure.category_object.CategoryObject, sage.structure.sage_object.SageObject, object]
and reading the code, it's completely unclear how
parent(phi)
got those module categories attached to it. It would have to happen somewhere insage.modules.vector_space_homspace.VectorSpaceHomspace, sage.modules.free_module_homspace.FreeModuleHomspace
but none of those classes have an__init__
.
The setting of the category for a homset is handled generically in Homset.init.
Cheers, Nicolas
Description changed:
---
+++
@@ -40,3 +40,5 @@
...
TypeError: unsupported operand parent(s) for '*': 'Finite Field of size 7' and 'Set of Morphisms (Linear Transformations) from Vector space of dimension 2 over Finite Field of size 7 to Vector space of dimension 2 over Finite Field of size 7'
+
+Update 2016/09/20: things have gotten even worse. Now 2*phi
does not work anymore.
Having a brief look at the code, MatrixMorphism
implements a __mul__
method to handle multiplication by other types of morphisms. But this prevents the coercion model to take over when needed!
Instead, MatrixMorphism
should implement _mul_
for basic multiplication, handle multiplication by other types of morphisms by coercion, and implement _lmul_
or _acted_upon
(I never quite remember from the top of my head which one should be used in this situation) to implement multiplication by scalar).
Setting new milestone based on a cursory review of ticket status, priority, and last modification date.
So far, so good. But:
In particular this prevents illustrating Cayley-Hamilton on the morphism side:
Update 2016/09/20: things have gotten even worse. Now
2*phi
does not work anymore.CC: @tscrim
Component: linear algebra
Issue created by migration from https://trac.sagemath.org/ticket/16830