Ask Your Question
1

Defining a graded vector space

asked 2023-07-01 03:29:04 +0100

adi gravatar image

updated 2023-07-05 00:42:04 +0100

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!

edit retag flag offensive close merge delete

Comments

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

John Palmieri gravatar imageJohn Palmieri ( 2023-07-02 22:23:07 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2023-07-04 23:54:42 +0100

adi gravatar image

Saving for posterity. The following code does the job:

class Element(GradedLieAlgebra.Element):

    def degree(self):

        l = [m for m in self]
        monomials = [x[0] for x in l]
        dictionary = self.parent().name_degree_map
        degrees=self.parent()._degrees

        values = [dictionary[key] for key in monomials if key in dictionary]

        return max(values)
edit flag offensive delete link more

Comments

GradedLieAlgebra is just the name of the parent class.

adi gravatar imageadi ( 2023-07-04 23:55:11 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2023-07-01 01:06:12 +0100

Seen: 276 times

Last updated: Jul 05 '23