Geometric Algebra

Implements a MultiVector object and its basic manipulations. This module also provides a GeometricAlgebra class to have a workspace for multivectors instance.

Classes

class geometric_algebra.GeometricAlgebra(dim: int = 3)

Implements a geometric algebra of a given dimension.

In most cases, you won’t have to manipulate this object.

Print a GeometricAlgebra instance will display the basis blades of the algebra.

Attributes

dimint

The dimension of the algebra. This will create the basis blades of the algebra.

nb_bladesint

The number of basis blades the algebra has.

blades_by_gradelist

The number of basis blades per grade. e.g. for a 3D-algebra, it will be [1, 3, 3, 1]

blades_idslist

It contains the ids of the basis blades. e.g. for a 2D-algebra, the basis blades are: s, e1, e2, e12 so the ids will be: [(), (1,), (2,), (1, 2)].

bladesdict

This dictionnary contains the basis blades: {name: value} where name is a string (e.g. 's', 'e1', 'e2' etc) and value the associated MultiVector instance.

Methods

__init__(dim: int = 3)

Constructor method.

Parameters

dimint, optionnal

The wanted dimension if the geometric algebra. By default, this will generate a three dimensional one.

get_grade(grade: int)

Returns the first and the last index of the researched grade. It can be useful if you search all the k-vectors of a given algebra, then you give the grade (i.e. k) and this method will return you the index of the first k-vector and the index of the last k-vector of your algebra.

Parameters

gradeint

The grade you are searching for.

Returns

outtuple

The output is a tuple composed of two elements. The first one is the first index and the second one, the last.

Exemples

If we work in a three-dimensionnal algebra:

>>> geo_alg = GeometricAlgebra(3)
>>> geo_alg.get_grade(2)
(4, 6)

Indeed, the first bivector (i.e. e12) is at index 4 and the last one (i.e. e23) is at 6.

class geometric_algebra.MultiVector(geo_alg: GeometricAlgebra, value=None)

An element of the geometric algebra.

The following operators have been overloaded:

  • the addition self + other

  • the substraction self - other

  • the geometric product self * other

  • the outer product self ^ other

  • the inner product self | other

  • the scalar division self / scalar

Some others manipulations are available:

  • the projection on grade k my_multivector(k)

  • the norm abs(my_multivector)

  • the inversion my_multivector.inverse()

  • the reversion \(A^{\dagger}\) ~my_multivector

  • the dual calculation my_multivector.dual()

  • the grade involution my_multivector.grade_involution()

Attributes

geo_algGeometricAlgebra

The geometric algebra to which the multivector belongs.

valuenp.array

The coefficients on each basis blade.

Methods

__init__(geo_alg: GeometricAlgebra, value=None)

Constructor method.

Note

value must be transtypable into an numpy.array.

Parameters

geo_algGeometricAlgebra

The algebra to which the multivector belongs.

value

The coefficients of the multivector.

__call__(*grades)

Projects the multivector on the basis blades of given grades.

Parameters

*grades

The grades on which the multivector will be project.

Returns

outMultiVector

The result of the projection.

Exemples

Let my_mv be a multivector such that my_mv = 1 + (2^e1) + (3^e2) + (4^e12) and let’s see some projections:

>>> my_mv = 1 + (2^e1) + (3^e2) + (4^e12)
>>> my_mv(0)  # projection on scalar
1
>>> my_mv(1)  # projection on vectors
(2^e1) + (3^e2)
>>> my_mv(0, 2)  # projection on scalar and bivectors
1 + (4^e12)
__getitem__(index: int)

Returns the component at the given index.

Parameters

indexint

The index of the desired component.

Returns

outfloat

The desired component.

copy()

Create a deep copy of the instance.

Returns

outMultiVector

The copy of the instance.

dual()

Compute the dual multivector.

Returns

outMultiVector

The dual.

grade_involution()

Compute the grade involution of the multivector.

Returns

new_mvMultiVector

The result of the grade involution.

inverse()

Compute the inverse of a given multivector.

Returns

outMultiVector

The inverted multivector.

isspinor()

Tests if the multivector is a spinor, i.e. if all its blade have even grade.

Returns

outbool

It equals to True if the multivector is a spinor, False else.

Exemples

Let’s show you a complete exemple of a manipulation of MultiVector. You must start by importing the module:

>>> import gscrew
>>> from gscrew.geometric_algebra import GeometricAlgebra, MultiVector
>>> ga = GeometricAlgebra(3)    # you should give the dimension of the algebra
>>> locals().update(ga.blades)  # import the basis blades e.g. s, e1, e2, e3, e12 etc

Then you have fully initialize the module. To create a new MultiVector instance, you have two possibilities. The first one is also the easiest:

>>> my_mv = 1 + 1*e1 + 5*e2 + (1/5) * e13

You can also call the constructor method manually:

>>> my_mv = MultiVector(geo_alg, (1, 1, 5, 0, 0, 1/5, 0, 0))

Warning

In the second case you have to give all the coefficients and the GeometricAlgebra instance.

Note

When you create a new MultiVector by using the basis blades, the new instance inherits the geometric algebra of the basis blades.