Ask Your Question

Is it possible to return the grade of a multivector?

asked 2024-04-28 00:43:27 +0200

anon2203 gravatar image

I have the following code:

from sage.algebras.clifford_algebra import CliffordAlgebra
from sage.quadratic_forms.quadratic_form import QuadraticForm
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

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
print(u.grade(1)) #outputs t*e0+x*e1+y*e2+z*e3
print(u.grade(2)) #outputs f01*e0*e1+f02*e0*e2+f03*e0*e3+f12*e1*e2+f13*e1*e3+f23*e2*e3


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2024-04-28 04:46:29 +0200

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


and [ 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 == 1)

which returns

t*e0 + x*e1 + y*e2 + z*e3
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2024-04-28 00:43:27 +0200

Seen: 126 times

Last updated: Apr 28