# How to use forgetful functors effectively in Sage?

I am trying to define a linear operator on a graded commutative algebra in Sage. The only way I know to do this is to forget the multiplication on the algebra, and then to define a linear operator in the underlying vector space.

Here is some Sage code, with output:

sage: A.<h1, h2> = GradedCommutativeAlgebra(QQ, degrees=(1, 1))
sage: A.category()
Category of graded algebras over Rational Field
sage: F(A).category()
Category of graded algebras over Rational Field


Evidently Sage forgets the multiplication on the graded commutative algebra A, but then immediately re-remembers the multiplication, so that the forgetful functor applied to A simply returns A again?

I have tried many variations on this code, e.g. switching to a forgetful functor landing in Q-vector spaces rather than graded Q-modules, ForgetfulFunctor(A.category(), Modules(QQ).Graded()), yields the error message:

TypeError: 'GCAlgebra_with_category' object has no attribute 'vector_space'


What am I missing here?

Even if this odd behavior of forgetful functors can't be figured out, I would be satisfied with another way to get what I want in the end: I am trying to define the Hodge star operator on the Chevalley-Eilenberg DGA of some specific Lie algebras given by specific presentations. While Sage supports the Hodge star on the differential forms on a manifold, it is not obvious how to write down an explicit Lie group whose Lie algebra is any specific one in this family of Lie algebras, and our Lie algebras are also defined over finite fields, so we would prefer to not have the restriction to characteristic zero that comes with the differential forms on a manifold.

edit retag close merge delete

Forgetful functors in Sage might not support this. Most algebras have a method module_morphism which can be used to define linear operators, but GradedCommutativeAlgebra does not. Could you work with ExteriorAlgebra instead? It already defines a method hodge_dual which might be useful.
Another option is to define a Python function f that explicitly computes the image of an element of A under the linear operator (you get an explicit representation of an element using e.g. h1.dict()), and then turn it into a morphism in a suitable category using SetMorphism. For example, sage.categories.morphism.SetMorphism(Hom(A, A, Modules(A.base_ring())), f).