Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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!