ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 28 Apr 2024 00:43:27 +0200Is it possible to return the grade of a multivector?https://ask.sagemath.org/question/77112/is-it-possible-to-return-the-grade-of-a-multivector/ 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
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
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
etc...anon2203Sun, 28 Apr 2024 00:43:27 +0200https://ask.sagemath.org/question/77112/Symbolic variables with Clifford algebrahttps://ask.sagemath.org/question/59697/symbolic-variables-with-clifford-algebra/Hello, a similar question was asked previously, but I am unable to use multiple symbolic variables with the answer. What I would like to do is the following:
sage: Q = QuadraticForm(ZZ,2,[1,1,1])
sage: Cl.<x,y> = CliffordAlgebra(Q)
Then, I would like to define two symbolic `a` and `b` variables
sage: a*x+b*y
such that this output is produced:
sage: (a*x+b*y)*(a*x+b*y)
a^2+b^2
How do I declare `a` and `b` so that this is possible?
---
I have tried `a, b = var('a b')` but `a*x` gives an error
sage: a*x
TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and 'The Clifford algebra of the Quadratic form in 2 variables over Integer Ring with coefficients:
[ 1 1 ]
[ * 1 ]'
I have also tried `R.<a> = PolynomialRing(ZZ)` and it works for 1 variable. But if I also tried to add `b`, it fails
sage: R.<a,b> = PolynomialRing(ZZ)
sage: a*x+b*y
TypeError: unsupported operand parent(s) for +: 'Multivariate Polynomial Ring in a, b over Integer Ring' and 'The Clifford algebra of the Quadratic form in 2 variables over Integer Ring with coefficients:
[ 1 1 ]
[ * 1 ]'anon2203Thu, 11 Nov 2021 21:32:25 +0100https://ask.sagemath.org/question/59697/How can I manipulate Clifford Algebra elements symbolically?https://ask.sagemath.org/question/75259/how-can-i-manipulate-clifford-algebra-elements-symbolically/**Problem**
Sometimes I would like to run functions from the Expression class on a Clifford algebra element. For example, simplification:
<pre><code>qf = DiagonalQuadraticForm(SR,[1,1,1])
Cl.<e1,e2,e3> = CliffordAlgebra(qf)
u, v = var(‘u v’)
((sin(u)^2 + cos(u)^2)*e1).simplify_full()
</code></pre>
I receive the error:
<pre><code>---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [91], line 4
1 #u,v = var('u v')
2 #SR(e1)
3 #e1.simplify_full()
----> 4 ((sin(u)**Integer(2) + cos(u)**Integer(2))*e1).simplify_full()
File /ext/sage/10.2/src/sage/structure/element.pyx:489, in sage.structure.element.Element.__getattr__()
487 AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'...
488 """
--> 489 return self.getattr_from_category(name)
490
491 cdef getattr_from_category(self, name) noexcept:
File /ext/sage/10.2/src/sage/structure/element.pyx:502, in sage.structure.element.Element.getattr_from_category()
500 else:
501 cls = P._abstract_element_class
--> 502 return getattr_from_other_class(self, cls, name)
503
504 def __dir__(self):
File /ext/sage/10.2/src/sage/cpython/getattr.pyx:357, in sage.cpython.getattr.getattr_from_other_class()
355 dummy_error_message.cls = type(self)
356 dummy_error_message.name = name
--> 357 raise AttributeError(dummy_error_message)
358 cdef PyObject* attr = instance_getattr(cls, name)
359 if attr is NULL:
AttributeError: 'CliffordAlgebra_with_category.element_class' object has no attribute 'simplify_full'
</code></pre>
The behavior I would like is to treat e1, e2, and e3 as symbols. But SR(e1) throws `TypeError: Unable to convert e1 to a symbolic expression`.
**Why I think this should work**
An analogous addition of structure preserves simplification operations, namely with vectors: `vector([sin(u)^2 + cos(u)^2,u]).simplify_full()` returns (1,u).
**Current Workaround**
My current workaround is to extract the coefficients, map them with the operations in question, and then recreate the Clifford algebra term.
<pre><code>def lift(fxn):
def fxn_aux(ga_term, *args):
a,b,c,d,e,f,g,h = [fxn(x, *args) for x in ga_term.dense_coefficient_list()]
return a + b*e1 + c*e2 + d*e3 + e*e1*e2 + f*e1*e3 + g*e2*e3 + h*e1*e2*e3
return fxn_aux
simp = lift(Expression.simplify_full)
ga_diff = lift(diff)
u,v = var('u v')
s = cos(u)*e1+sin(u)*cos(v)*e2+sin(u)*sin(v)*e3
show(simp(3 + (cos(u)^2 + sin(u)^2)*e1))
show(ga_diff(s,u))
</code></pre>
**Question**
Is there a more elegant or canonical way to do this?
scottviteriSun, 31 Dec 2023 21:57:02 +0100https://ask.sagemath.org/question/75259/Why is addition between a symbol and a Clifford algebra element unsupported?https://ask.sagemath.org/question/74871/why-is-addition-between-a-symbol-and-a-clifford-algebra-element-unsupported/**To reproduce error:**
from sage.algebras.clifford_algebra import CliffordAlgebra;
from sage.quadratic_forms.quadratic_form import QuadraticForm;
from sage.rings.rational_field import QQ
QF = QuadraticForm(QQ, 3, [1, 0, 0, 1, 0, 1]);
Cl.<e1,e2,e3> = CliffordAlgebra(QF);
i = var('i');
print(i*e1)
**Error:**
File ~/LocalSoftware/sage/src/sage/structure/coerce.pyx:1276, in sage.structure.coerce.CoercionModel.bin_op()
1274 # We should really include the underlying error.
1275 # This causes so much headache.
-> 1276 raise bin_op_exception(op, x, y)
1277
1278 cpdef canonical_coercion(self, x, y) noexcept:
TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and 'The Clifford algebra of the Quadratic form in 3 variables over Rational Field with coefficients:
[ 1 0 0 ]
[ * 1 0 ]
[ * * 1 ]'
**Question:** How does symbolic computation work under the hood in sage? Does this problem exist for elements of other algebras as well?
**My actual objective:** I would like to derive the trigonometric parametrization for the sphere by apply the rotor of e1*e2 and the rotor of e2*e3 to e1, but to do so I would need to keep the two angles symbolic. Of course I could derive the answer by hand, but I am trying to get feel for where SageMath is useful.scottviteriFri, 15 Dec 2023 22:20:13 +0100https://ask.sagemath.org/question/74871/Representation of Clifford algebrashttps://ask.sagemath.org/question/61973/representation-of-clifford-algebras/Is there a way of defining a matrix representation of Clifford algebras in sage?
For example, $Cl(3)$ is isomorphic to $M(2,\mathbb{C})$. Such isomorphism can be implemented by $\rho(e_i) = \sigma_i$, where $\sigma_i$ are the [Pauli matrices](https://en.wikipedia.org/wiki/Pauli_matrices).
In general, I would like to define an isomorphism $\rho :Cl(V,Q) \to M(n,\mathbb{K})$ and go back and forward between elements of $Cl(V,Q)$ and $M(n,\mathbb{K})$.
Is it possible in sage? I didn't find any hint on the documentation.cav_rtThu, 14 Apr 2022 22:23:12 +0200https://ask.sagemath.org/question/61973/Exponential in Clifford algebrahttps://ask.sagemath.org/question/59711/exponential-in-clifford-algebra/Hello, I am trying to take the exponential of `A+B*i` in Clifford algebra (isomorphic to the complex numbers) .
Code is:
sage: R.<A,B> = PolynomialRing(ZZ);
sage: Q = QuadraticForm(R,1,[-1]);
sage: Cl.<i> = CliffordAlgebra(Q);
sage: exp(A+B*i)*exp(A-B*i)
I would expect it to output `exp(2*A)`, but it produces this error:
TypeError: cannot coerce arguments: no canonical coercion from The Clifford algebra of the Quadratic form in 1 variables over Multivariate Polynomial Ring in A, B over Integer Ring with coefficients:
[ 1 ] to Symbolic Ringanon2203Fri, 12 Nov 2021 14:41:07 +0100https://ask.sagemath.org/question/59711/Morphism from FiniteRankFreeModule to CliffordAlgebrahttps://ask.sagemath.org/question/51004/morphism-from-finiterankfreemodule-to-cliffordalgebra/ Suppose you have a finite rank free module with a basis:
M = FiniteRankFreeModule(QQ, 4, name='M', start_index=1)
m = M.basis('m');
and a Clifford algebra
Q = QuadraticForm(QQ,-2*matrix.identity(4))
V.<e1,e2,e3,e4> = CliffordAlgebra(Q)
Is there a way to implement the quantization map $q:T(M)\to V$ from the tensor algebra to the Clifford algebra?
It should satisfy $q(1) = 1$, $q(m[i]) = e_i$ and $q(a \otimes b) = q(a)*q(b)$.RStormSat, 25 Apr 2020 13:25:35 +0200https://ask.sagemath.org/question/51004/Quaternions Missing Important Functionality?https://ask.sagemath.org/question/34587/quaternions-missing-important-functionality/I use quaternions and Clifford algebras frequently for solving PDE boundary value problems as well as things like reflections, rotations etc. The underlying field for my quaternions is almost always either the complex numbers or the symbolic ring.
I am making an attempt to use them in Sage but I've run into a couple of obstacles that have given me pause. The absolute first things I looked for were,
1) scalar part or real part of the quaternion. Where is this function? I stumbled upon turning it into a list or vector but I presume that just taking the scalar part would be more efficient than dumping all the coefficients. For matrix representations it's often just the trace of the matrix. Correspondingly obtaining the vector part should be a standard function as well.
2) Quaternion automorphisms and anti-automorphisms? where are they? Yes we have conjugate which is both a method and an external function but what about the reversion and involution and the many other automorphisms? I don't expect to have to multiply by a bunch of unit vectors to get them for efficiency reasons. Also how do I distinguish between the quaternion conjugate and the complex conjugate of each of it's elements? This is a very important distinction that I would not know how to do without stripping out it's components and then remapping it.
3) Constructing a quaternion from coefficients. The only examples I've seen require explicit multiplications like
q = q0 + q1 * i + q2 * j + q3 * k . That doesn't seem efficient.
4) quaternions as elements of enclosing matrices and vectors. This would be very helpful since you could generate any Clifford algebra with this and it's often easier to analyze the components of said algebra that are isomorphic to Quaternions or Biquaternions in the complex case. Moreover I need to be able to do this for quaternions over the symbolic ring. It fails for me as this example from sage 7.3 shows:
<pre><code>
Q.<e1,e2,e3> = QuaternionAlgebra(SR, -1,-1)
var('x y z', domain='real')
q1 = x + x * I * e1
q2 = x - x * I * e1
v = vector([q1,q2])
</code></pre>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_36.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("US48ZTEsZTIsZTM+ID0gUXVhdGVybmlvbkFsZ2VicmEoU1IsIC0xLC0xKQp2YXIoJ3ggeSB6JywgZG9tYWluPSdyZWFsJykKcTEgPSB4ICsgeCAqIEkgKiBlMQpxMiA9IHggLSB4ICogSSAqIGUxCnYgPSB2ZWN0b3IoW3ExLHEyXSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpQ0ibdW/___code___.py", line 7, in <module>
exec compile(u'v = vector([q1,q2]) File "", line 1, in <module>
File "sage/modules/free_module_element.pyx", line 510, in sage.modules.free_module_element.vector (/data/AppData/SageMath/src/build/cythonized/sage/modules/free_module_element.c:5811)
TypeError: unsupported operand type(s) for ** or pow(): 'QuaternionAlgebra_ab' and 'int'
5) quaternion rotations. Most libraries will generate the unit quaternion that rotates in 3D space and/or have a function that applies it efficiently.
There are probably a few other things like generating a canonical matrix representation for a full quaternion and so forth. I actually wonder if the default quaternion package is the right tool for a physicist or an engineer or someone who wants to play around with the so called geometric algebra of Hestenes. It seems the perogatives of the scientist vs the algebraist are very very different. How efficient is this library? What if I had to multiply millions of quaternions? I'm guessing I'd be better off mapping it to complex matrices and invoking blas.
While most of the functionality can be added on via a little python programming, I am concerned about efficiency and consistency. Moreover item 4 is a bit of a quandary since it involves overloading a bunch of arithmetic operators and some new python classes and so forth.
I'm hoping someone will tell me that it's all there, I just wasn't able to find it in the documentation or so forth. Thanks for any help in advance.doomFri, 26 Aug 2016 04:11:21 +0200https://ask.sagemath.org/question/34587/symbolic constant in clifford algebrahttps://ask.sagemath.org/question/33763/symbolic-constant-in-clifford-algebra/ Dear all,
First of all I'd like to state that I am far from a SageMath expert. Right now, I am working on Clifford algebra's and I would like to do some computations with SageMath Cloud. Unfortunately, I experience the problem that when I define a symbolic constant, Sage doesn't know how to multiply this with elements in the Clifford algebra. This is the code that I'm using.
START CODE
C = ComplexField();
sage: Q = QuadraticForm(C, 3, [0,0,1,1,0,0])
sage: Cl.<x,y,z> = CliffordAlgebra(Q)
var('e')
e*x
END CODE
I get an error for e*x: ''unsupported operand parent(s) for '*': 'Symbolic Ring' and 'The Clifford algebra of the Quadratic form in 3 variables over Complex Field with 53 bits of precision with coefficients:''
Does anyone maybe know how to work around this? Maybe I am defining the variable all wrong?
Thank you very much!
Kind regards,
David
davidvanovereemMon, 13 Jun 2016 15:01:50 +0200https://ask.sagemath.org/question/33763/How to multiply symbolic constant with element in clifford algebra?https://ask.sagemath.org/question/33764/how-to-multiply-symbolic-constant-with-element-in-clifford-algebra/Dear all,
first I would like to state that I am only a beginner at using SageMath. Currently I am working on Clifford algebra's but unfortunately I'm experiencing a problem. I cannot find a solution in the documentation so I hope maybe someone here has an idea!
I would like to define a symbolic constant in the field of complex numbers, and multiply this with an element from the clifford algebra. Unfortunately, SageMath doesn't like this! This is the code that I'm using:
START CODE
sage: Q = QuadraticForm(CC, 3, [0,0,1,1,0,0])
sage: Cl.<x,y,z> = CliffordAlgebra(Q)
var('e')
e*x
END CODE
the operation e*x now gives me an error: ''TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and 'The Clifford algebra of the Quadratic form in 3 variables over Complex Field with 53 bits of precision with coefficients: ...''
Does anyone maybe have an idea how to work around this? Maybe I'm defing the symbolic constant all wrong?
Thank you very much! Kind regards,
David
davidvanovereemMon, 13 Jun 2016 15:07:26 +0200https://ask.sagemath.org/question/33764/