ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 20 Mar 2020 02:22:43 -0500Polynomials over Quaternions via Determinantshttps://ask.sagemath.org/question/50310/polynomials-over-quaternions-via-determinants/I currently trying to get polynomials over quaternions out of determinants of matrices. Example giving below:
> Q.<i,j,k> = QuaternionAlgebra(SR, -1, -1)
> A=matrix(4,4,[0,j,0,j,j,0,0,j,0,0,0,0,j,j,0,0])
> I=matrix.identity(4)
> P=(j\*A-x\*I)
> P.det()
But it doesn't work. Any idea?draksFri, 20 Mar 2020 02:22:43 -0500https://ask.sagemath.org/question/50310/How are symbolic derivatives composed in quaternions?https://ask.sagemath.org/question/49785/how-are-symbolic-derivatives-composed-in-quaternions/The scripts below were run in: Sage Cell Server, version: 'SageMath version 9.0, Release Date: 2020-01-01'
I am a new user of SageMath. I have previously used math packages, but SageMath is above and beyond all I have encountered before. It also has remarkably comprehensive documentation. In particular I have found Vector calculus with SageMath and Sage Reference Manual: Quaternion Algebras (insufficient karma to post links). I note that the latter is dated Jan 01, 2020. The examples below are drawn from those two sources. I am searching for calculus tools in the quaternion algebra package. I want to do something like this, which works in EuclideanSpace:
Sage: %display latex
Sage: from sage.manifolds.operators import *
Sage: E.<x,y,z> = EuclideanSpace()
Sage: F = E.scalar_field(function('f')(x,y,z), name='F')
Sage: grad(F).display()
grad(F) = d(f)/dx e_x + d(f)/dy e_y + d(f)/dz e_z The EucliedanSpace also knows how to pretty-print it with LaTeX.
This is as close as I have gotten with quaternions:
Sage: N.<a,b,c,d,y> = QQ[]
Sage: Q.<i,j,k> = QuaternionAlgebra(SR,-1,-1)
Sage: def qd(u):
Sage: w = j*(diff(u[0],y) + diff(u[1],y)*i + diff(u[2],y)*j + diff(u[3],y)*k)
Sage: return w
Sage: b = sin(y)
Sage: f = a+b*i+c*j+d*k
Sage: t = qd(f)
Sage: show(t)
(-cos(y))*k
This is the correct quaternion result, but I want to change the declaration of "b" so that I get something like
**(-d(f)/dy) * k**. Here are the problems that concern me.
1. "diff" does not correctly handle "f" as an argument. It returns 0.
2. The definition in the function "qd" (quaternion derivative) of w should contain 3 more rows, but this one is enough to illustrate my main issue: If "b" is not defined as a specific function (e.g. sin(y)), "diff" returns 0. I would like it to return the derivative display formula, as the Euclidean example does.
3. Replacing show(t) with t.display() returns error messages such as "object has no attribute 'blah_blah'" and "raise AttributeError(dummy_error_message)." There may still be some work in progress here.
I hope there is presently a solution within SageMath. Please adapt the second script or give me an example script.
If not, I am reasonably competent with Python 3. If someone can give me links to the relevant source for the EuclideanSpace methods of "grad" and "function" and to the QuaternionAlgebra source for "diff," I may be able to add a method or two to the QuaternionAlgebra implementation and advance the development of that part of the system, or at least register myself as a beta-tester.
Thanks very much for any help you can give me!
quirkyTue, 04 Feb 2020 13:31:21 -0600https://ask.sagemath.org/question/49785/Quaternion * integerhttps://ask.sagemath.org/question/44869/quaternion-integer/ how can i multiply my own quaternion group elements with a normal integer?
it says this:
unsupported operand parent(s) for +: 'Integer Ring' and '<class 'quater'>'SpreeterThu, 03 Jan 2019 09:36:01 -0600https://ask.sagemath.org/question/44869/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.doomThu, 25 Aug 2016 21:11:21 -0500https://ask.sagemath.org/question/34587/quaternions not hashable?https://ask.sagemath.org/question/33783/quaternions-not-hashable/ If I try to take the hash of a quaternion, I get an error:
<pre>
sage: D.<i,j,k>=QuaternionAlgebra(QQ,-1,-3)
sage: hash(i)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-037418ebb374> in <module>()
----> 1 hash(i)
TypeError: unhashable type: 'sage.algebras.quatalg.quaternion_algebra_element.QuaternionAlgebraElement_rational_field'
</pre>
I seem to remember quaternions being hashable in a previous version of Sage (I think I was using 6.7 before). Is it intentional that quaternions are now unhashable, or is this an omission?dgulottaTue, 14 Jun 2016 11:18:12 -0500https://ask.sagemath.org/question/33783/How can I define a function with quaternion argument, and other non-vector inputhttps://ask.sagemath.org/question/30025/how-can-i-define-a-function-with-quaternion-argument-and-other-non-vector-input/I've been using Sage for 3 weeks so please bear with me if this is an ignorant question.
There are lots of great tools for studying properties of quaternion algebras
http://doc.sagemath.org/html/en/reference/quat_algebras/sage/algebras/quatalg/quaternion_algebra.html
and also for doing computations in these algebras
http://doc.sagemath.org/html/en/reference/quat_algebras/sage/algebras/quatalg/quaternion_algebra_element.html
But I am interested in working with functions that move between quaternion algebras and other spaces.
For instance let's say I write
K.<d> = NumberField(x^2 + 1)
A.<i,j,k> = QuaternionAlgebra(K,-1,-1)
And let's say I want a function
$$f:A\rightarrow M_2(K), w+xi+yj+zij\mapsto (w,x,y,z).$$
How can define this function in such a way that I can enter something like
f(2*i+i*j)
and get as output
(0,2,0,1)
?
**This particular function is not very useful or interesting, I'm just using this to keep it simple. I'd also be interested in defining functions that go from one quaternion algebra to another, or from a quaternion algebra to a matrix ring, in such a way that I can compose these things.** It seems functions are generally expected to have vector input, but there is not always a straightforward way of turning elements of a domain into vectors (there is for matrices, but even this is tedious).
I feel there is probably a general principle addressing things like this but I'm not finding it.
j0equ1nnWed, 14 Oct 2015 21:44:52 -0500https://ask.sagemath.org/question/30025/How do I multiply quaternion and vector?https://ask.sagemath.org/question/28734/how-do-i-multiply-quaternion-and-vector/I started with this
N.<c,d,a1,a2,a3,a4,b1,b2,b3,b4,s> = QQ[]
H.<i,j,k> = QuaternionAlgebra(c,d)
a = a1 + a2 * i + a3 * j + a4 * k
b = b1 + b2 * i + b3 * j + b4 * k
a+b
a*b
but the next step does not work
gravity = vector([0, 0, 1])
a * gravity * a.conjugate()
uutzingerThu, 30 Jul 2015 20:33:17 -0500https://ask.sagemath.org/question/28734/How to do symbolic computation with quaternionshttps://ask.sagemath.org/question/9730/how-to-do-symbolic-computation-with-quaternions/I need to do symbolic computations with quaternions. Ideally I'd like to enter something like
Q.<i,j,k> = QuaternionAlgebra(QQ,-1,-1)
a=var('a')
b=var('b')
c=var('c')
q = a*i+b*j+c*k
But it doesn't work : TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and 'Quaternion Algebra (-1, -1) with base ring Rational Field'
Looks like SAGE doesn't know how to multiply a variable and a quaternion. Or should I specify the types of the variables ? How ?
Thanks for your help.
Gilles FalquetMon, 21 Jan 2013 20:37:05 -0600https://ask.sagemath.org/question/9730/