# Is it possible to return the grade of a multivector?

I have the following code:

from sage.algebras.clifford_algebra import CliffordAlgebra
from sage.symbolic.ring import SR

# Define the quadratic form for GA(3,1) over the Symbolic Ring
Q = QuadraticForm(SR, 4, [-1, 0, 0, 0, 1, 0, 0, 1, 0, 1])

# Initialize the GA(3,1) algebra over the Symbolic Ring
algebra = CliffordAlgebra(Q)

# Define the basis vectors
e0, e1, e2, e3 = algebra.gens()

# Define the scalar variables for each basis element
a, t, x, y, z, f01, f02, f03, f12, f23, f13, v, w, q, p, b = var('a t x y z f01 f02 f03 f12 f23 f13 v w q p b')

# Create a general multivector
u = a+t*e0+x*e1+y*e2+z*e3+f01*e0*e1+f02*e0*e2+f03*e0*e3+f12*e1*e2+f13*e1*e3+f23*e2*e3

# Print the results
print(u)


Instead of printing u, I would like to print only a specific grade of u? But there is no function ex: u.grade(1) that returns the grade. I am looking for a way to specify a grade and return it: for instance:

print(u.grade(0)) #outputs a


etc...

edit retag close merge delete

Sort by ยป oldest newest most voted

You can recover the degree of an element using the degree method. Your element u is not homogeneous, so u.degree() raises an error: "ValueError: element is not homogeneous". However, you can get the degree of each term in u: first, u.terms() returns

[a,
t*e0,
x*e1,
y*e2,
z*e3,
f01*e0*e1,
f02*e0*e2,
f03*e0*e3,
f12*e1*e2,
f13*e1*e3,
f23*e2*e3]


and [x.degree() for x in u.terms()] returns

[0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]


So if you want the terms in degree 1, for example, you can do:

sum(x for x in u.terms() if x.degree() == 1)


which returns

t*e0 + x*e1 + y*e2 + z*e3

more