# Defining a graded vector space

Hello all. I'm trying to define a (finite) graded vector space using SAGE. I've managed to set up a class which takes names and degrees as input parameters.

Example: My idea is that if we have names (x,y,z) with degrees (1,1,2), then this is supposed to be Q^2 + Q (taking the base ring to be Q). I am going to be building everything on the category of combinatorial free modules.

I have been struggling to define a method in the element class which is supposed to return the degree of a given expression by taking the maximum of the degrees of all the monomials. I have defined a dictionary (in the parent __init__ definition) which puts the name as key and degree as value. But how can I extract that information from any given arbitrary expression (say, B['x'] + B['y'])?

Example of successful code: (y+z).degree()

sage: 2

Thanks in advance!

Try imitating what is done in the Sage source code, in particular in https://github.com/sagemath/sage/blob....