{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Interfacing Other Mathematical Systems\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Geometric Algebra is known as a *universal algebra* because it subsumes several other mathematical systems. Two algebras commonly used by engineers and scientists are complex numbers and quaternions. These algebras can be subsumed as the even sub-algebras of 2 and 3 dimensional geometric algebras, respectively. This notebook demonstrates how `clifford` can be used to incorporate data created with these systems into geometric algebra." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Complex Numbers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given a two dimensional GA with the orthonormal basis,\n", "\n", "$$e_{i}\\cdot e_{j}=\\delta_{ij}$$\n", " \n", "\n", "The geometric algebra consists of scalars, two vectors, and a bivector , \n", "\n", "$$\\{\\underbrace{\\alpha}_{\\mbox{scalar}},\\qquad\\underbrace{e_{1},e_{2}}_{\\mbox{vector}},\\qquad\\underbrace{e_{12}}_{\\mbox{bivector}}\\}$$\n", " \n", "\n", "\n", "A complex number can be directly associated with a 2D spinor in the $e_{12}$\n", " -plane, \n", "\n", "$$\\underbrace{\\mathbf{z}=\\alpha+\\beta i}_{\\mbox{complex number}}\\quad\\Longrightarrow\\quad\\underbrace{Z=\\alpha+\\beta e_{12}}_{\\mbox{2D spinor}}$$\n", "\n", "\n", " \n", "The even subalgebra of a two dimensional geometric algebra is isomorphic to the complex numbers. We can setup translating functions which converts a 2D spinor into a complex number and vice-versa. In two dimensions the spinor can be also be mapped into vectors if desired. \n", "\n", "Below is an illustration of the three different planes, the later two being contained within the geometric algebra of two dimensions, $G_2$. Both spinors and vectors in $G_2$ can be modeled as points on a plane, but they have distinct algebraic properties. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from IPython.display import Image\n", "Image(url='_static/2dmap.svg')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from numpy import pi,e\n", "import clifford as cf\n", "layout, blades = cf.Cl(2) # instantiate a 2D- GA\n", "locals().update(blades) # put all blades into local namespace\n", "\n", "\n", "def c2s(z):\n", " '''convert a complex number to a spinor'''\n", " return z.real + z.imag*e12\n", "\n", "def s2c(S):\n", " '''convert a spinor to a complex number'''\n", " S0 = float(S(0))\n", " S2 = float(-S|e12)\n", " return S0 + S2*1j\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Convert a complex number to a spinor " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "c2s(1+2j)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Convert a spinor to a complex number" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "s2c(1+2*e12)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make sure we get what we started with when we make a round trip" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "s2c(c2s(1+2j)) == 1+2j" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The spinor is then mapped to a vector by choosing a reference direction. This may be done by left multiplying with $e_{1}$\n", " .\n", "\n", "$$Z\\Longrightarrow e_{1}Z=e_{1}\\alpha+\\beta e_{1}e_{12}=\\underbrace{\\alpha e_{1}+\\beta e_{2}}_{\\mbox{vector}}$$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "s = 1+2*e12\n", "e1*s" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Geometrically, this is interpreted as having the spinor rotate a specific vector, in this case $e_1$. Building off of the previously defined functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def c2v(c):\n", " '''convert a complex number to a vector'''\n", " return e1*c2s(c)\n", "\n", "def v2c(v):\n", " '''convert a vector to a complex number'''\n", " return s2c(e1*v) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "c2v(1+2j)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "v2c(1*e1+2*e2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Depending on your applications, you may wish to have the bivector be an argument to the `c2s` and `s2c` functions. This allows you to map input data given in the form of complex number onto the planes of your choice. For example, in three dimensional space there are three bivector-planes; $e_{12}, e_{23}$ and $e_{13}$, so there are many bivectors which could be interpreted as the unit imaginary. \n", "\n", "Complex numbers mapped in this way can be used to enact rotations within the specified planes. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", "import clifford as cf\n", "layout, blades = cf.Cl(3)\n", "locals().update(blades)\n", "\n", "def c2s(z,B):\n", " '''convert a complex number to a spinor'''\n", " return z.real + z.imag*B\n", "\n", "def s2c(S,B):\n", " '''convert a spinor to a complex number'''\n", " S0 = float(S(0))\n", " S2 = float(-S|B)\n", " return S0 + S2*1j" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "c2s(1+2j,e23)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "c2s(3+4j,e13)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This brings us to the subject of quaternions, which are used to handle rotations in three dimensions much like complex numbers do in two dimensions. With geometric algebra, they are just spinors acting in a different geometry. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Quaternions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "