galgebra.mv
Multivector and Linear Multivector Differential Operator
Members
- class galgebra.mv.Mv(self, *args, ga, recp=None, **kwargs)[source]
Bases:
GaPrintable
Wrapper class for multivector objects (
self.obj
) so that it is easy to overload operators (*
,^
,|
,<
,>
) for the various multivector products and for printing.Also provides a constructor to easily instantiate multivector objects.
Additionally, the functionality of the multivector derivative have been added via the special vector
grad
so that one can take the geometric derivative of a multivector functionA
by applyinggrad
from the left,grad*A
, or the rightA*grad
for both the left and right derivatives. The operator between thegrad
and the ‘A’ can be any of the multivector product operators.If
f
is a scalar functiongrad*f
is the usual gradient of a function. IfA
is a vector functiongrad|f
is the divergence ofA
and-I*(grad^A)
is the curl ofA
(I is the pseudo scalar for the geometric algebra)- obj
The underlying sympy expression for this multivector
- Type:
sympy.core.Expr
Note this constructor is overloaded, based on the type and number of positional arguments:
- class Mv(*, ga, recp=None)
Create a zero multivector
- class Mv(expr, /, *, ga, recp=None)
Create a multivector from an existing vector or sympy expression
- class Mv(coeffs, grade, /, ga, recp=None)
Create a multivector constant with a given grade
- class Mv(name, category, /, *cat_args, ga, recp=None, f=False)
Create a multivector constant with a given category
- class Mv(name, grade, /, ga, recp=None, f=False)
Create a multivector variable or function of a given grade
- class Mv(coeffs, category, /, *cat_args, ga, recp=None)
Create a multivector variable or function of a given category
*
and/
in the signatures above are python 3.8 syntax, and respectively indicate the boundaries between positional-only, normal, and keyword-only arguments.- Parameters:
ga (Ga) – Geometric algebra to be used with multivectors
recp (object, optional) – Normalization for reciprocal vector. Unused.
name (str) – Name of this multivector, if it is a variable or function
coeffs (sequence) – Sequence of coefficients for the given category. This is only meaningful
category (str) –
One of:
"grade"
- this takes an additional argument, the grade to create, incat_args
"scalar"
"vector"
"bivector"
/"grade2"
"pseudo"
"mv"
"even"
/"spinor"
"odd"
f (bool, tuple) – True if function of coordinates, or a tuple of those coordinates. Only valid if a name is passed
coords –
This argument is always accepted but ignored.
It is incorrectly described internally as the coordinates to be used with multivector functions.
- static setup(ga: Ga) Tuple[Mv, List[Mv], Mv] [source]
Set up constant multivectors required for multivector class for a given geometric algebra, ga.
- static Mul(A: Mv, B: Mv, op: str) Mv [source]
Function for all types of geometric multiplications called by overloaded operators for
*
,^
,|
,<
, and>
.
- collect(deep=False) Mv [source]
group coeffients of blades of multivector so there is only one coefficient per grade
- is_blade() bool [source]
True is self is blade, otherwise False sets self.blade_flg and returns value
- is_versor() bool [source]
Test for versor (geometric product of vectors)
This follows Leo Dorst’s test for a versor. Leo Dorst, ‘Geometric Algebra for Computer Science,’ p.533 Sets self.versor_flg and returns value
- get_coefs(grade: int) List[Expr] [source]
Like
blade_coefs(self.Ga.mv_blades[grade])
, but requires all components to be of that grade.- Raises:
ValueError: – If the multivector is not of the given grade.
- blade_coefs(blade_lst: List[Mv] = None) List[Expr] [source]
For a multivector, A, and a list of basis blades, blade_lst return a list (sympy expressions) of the coefficients of each basis blade in blade_lst
- proj(bases_lst: List[Mv]) Mv [source]
Project multivector onto a given list of bases. That is find the part of multivector with the same bases as in the bases_lst.
- undual() Mv [source]
Inverse method to multivector method .dual(), so both A.dual().undual() and A.undual().dual return A.
- g_invol() Mv [source]
Returns grade involute of multivector self; negates self’s odd grade part but preserves its even grade part.
Grade involution is its own inverse operation.
- ccon() Mv [source]
Returns Clifford conjugate of multivector self, i.e. returns the reverse of self’s grade involute.
Clifford conjugation is its own inverse operation.
- sp(B, switch='') Expr [source]
Returns scalar product of multivectors self and B.
Object returned is a real expression, not a 0-vector.
switch can be either ‘’ (the empty string) or ‘rev’. The latter causes left factor self to be reversed before its product with B is taken.
- Grad(coords, mode: str = '*', left: bool = True) Mv [source]
Returns various derivatives (
*
,^
,|
,<
,>
) of multivector functions with respect to arbitrary coordinates, ‘coords’.This would be used where you have a multivector function of both the basis coordinate set and and auxiliary coordinate set. Consider for example a linear transformation in which the matrix coefficients depend upon the manifold coordinates, but the vector being transformed does not and you wish to take the divergence of the linear transformation with respect to the linear argument.
- exp(hint: str = '-') Mv [source]
Only works if square of multivector is a scalar. If square is a number we can determine if square is > or < zero and hence if one should use trig or hyperbolic functions in expansion. If square is not a number use ‘hint’ to determine which type of functions to use in expansion
- Fmt(fmt: int = 1, title: str = None) GaPrintable [source]
Set format for printing of multivectors
fmt=1 - One multivector per line
fmt=2 - One grade per line
fmt=3 - one base per line
Usage for multivector
A
example is:A.Fmt('2', 'A')
output is:
'A = '+str(A)
with one grade per line. Works for both standard printing and for latex.
- qform() Expr [source]
Returns the quadratic form of multivector self.
Return value is a real SymPy expression, NOT a GAlgebra 0-vector.
Expression necessarily represents a nonnegative number only when self’s geometric algebra has a Euclidean metric.
- norm2(hint: str = '0') Expr [source]
Returns the normsquared of multivector self, defined as the absolute value of the quadratic form at self.
Return value is a real SymPy expression, NOT a GAlgebra 0-vector. Whether numeric or symbolic, A.norm2() always represents a nonnegative number.
String values ‘+’, ‘-’, or ‘0’ of hint respectively determine whether the quadratic form, the absolute value of which is the norm squared, should be regarded as nonnegative, nonpositive, or of unknown sign, except when that quantity’s sign can be determined by other considerations, such as the metric being Euclidean.
- norm(hint='0') Expr [source]
Returns the norm of multivector self, defined as the square root of self’s norm squared.
Whether numeric or symbolic, returned value is a real SymPy expression that necessarily represents a nonnegative number. Returned value is NOT a GAlgebra 0-vector.
String values ‘+’, ‘-’, or ‘0’ of hint respectively determine whether the quadratic form from which the norm ultimately derives should be regarded as nonnegative, nonpositive, or of unknown sign, except when the quadratic form’s sign can be determined by other considerations, such as the metric being Euclidean.
- mag2() Expr [source]
Returns the magnitude squared of multivector self, defined as the sum of the absolute values of the norm squareds of self’s grade parts.
Returned value is a real SymPy expression, NOT a GAlgebra 0-vector. Expression necesssarily represents a nonnegative number.
The magnitude squared differs from the norm squared of self when the metric is non-Euclidean.
- mag() Expr [source]
Returns the magnitude of multivector self, defined as the square root of the magnitude squared.
The magnitude necessarily agrees with the norm only when the metric is Euclidean. Otherwise the magnitude is greater than or equal to the norm.
- shirokov_inverse() Mv [source]
Iterative algorithm for the inverse following Theorem 4 (page 17) in https://arxiv.org/abs/2005.04015
- hitzer_inverse() Mv [source]
Efficient algorithm for the inverse in n<6 following Eckhard Hitzer, Stephen Sangwine (2017) ‘Multivector and multivector matrix inverses in real Clifford algebras’
- galgebra.mv.compare(A: Mv, B: Mv) Expr | int [source]
Determine if
B = c*A
where c is a scalar. If true return c otherwise return 0.
- class galgebra.mv.Dop(*args, ga: Ga, cmpflg: bool = False, debug: bool = False)[source]
Bases:
_BaseDop
Differential operator class for multivectors. The operators are of the form
\[D = D^{i_{1}...i_{n}}\partial_{i_{1}...i_{n}}\]where the \(D^{i_{1}...i_{n}}\) are multivector functions of the coordinates \(x_{1},...,x_{n}\) and \(\partial_{i_{1}...i_{n}}\) are partial derivative operators
\[\partial_{i_{1}...i_{n}} = \frac{\partial^{i_{1}+...+i_{n}}}{\partial{x_{1}^{i_{1}}}...\partial{x_{n}^{i_{n}}}}.\]If \(*\) is any multivector multiplicative operation then the operator D operates on the multivector function \(F\) by the following definitions
\[D*F = D^{i_{1}...i_{n}}*\partial_{i_{1}...i_{n}}F\]returns a multivector and
\[F*D = F*D^{i_{1}...i_{n}}\partial_{i_{1}...i_{n}}\]returns a differential operator. If the
cmpflg
in the operator is set toTrue
the operation returns\[F*D = (\partial_{i_{1}...i_{n}}F)*D^{i_{1}...i_{n}}\]a multivector function. For example the representation of the grad operator in 3d would be:
\[\begin{split}D^{i_{1}...i_{n}} &= [e_x,e_y,e_z] \\ \partial_{i_{1}...i_{n}} &= [(1,0,0),(0,1,0),(0,0,1)].\end{split}\]See LaTeX documentation for definitions of operator algebraic operations
+
,-
,*
,^
,|
,<
, and>
.- Parameters:
- galgebra.mv.Nga(x, prec=5)[source]
Like
sympy.N()
, but also works on multivectorsFor multivectors with coefficients that contain floating point numbers, this rounds all these numbers to a precision of
prec
and returns the rounded multivector.
- galgebra.mv.cross(v1: Mv, v2: Mv) Mv [source]
If
v1
andv2
are 3-dimensional Euclidean vectors, compute the vector cross product \(v_{1}\times v_{2} = -I{\lp {v_{1}{\wedge}v_{2}} \rp }\).
- galgebra.mv.undual(A: Mv) Mv [source]
Equivalent to :meth: Mv.undual. Inverse function to multivector function dual, so both undual(dual(A)) and dual(undual(A)) return A.
- galgebra.mv.g_invol(A: Mv) Mv [source]
Equivalent to :meth: Mv.g_invol. - Returns grade involute of multivector A; negates A’s odd grade part but preserves its even grade part. - Grade involution is its own inverse operation.
- galgebra.mv.exp(A: Mv | Expr, hint: str = '-') Mv | Expr [source]
If
A
is a multivector thenA.exp(hint)
is returned. IfA
is a sympy expression the sympy expression \(e^{A}\) is returned (seesympy.exp()
).
- galgebra.mv.shirokov_inverse(A: Mv) Mv [source]
Equivalent to
Mv.shirokov_inverse()
- galgebra.mv.hitzer_inverse(A: Mv) Mv [source]
Equivalent to
Mv.hitzer_inverse()
- galgebra.mv.qform(A: Mv) Expr [source]
Equivalent to
Mv.qform()
.qform(A) returns the quadratic form at multivector A.
Returned value is a real SymPy expression, NOT a GAlgebra 0-vector.
Expression necessarily represents a nonnegative number only when A’s geometric algebra has a Euclidean metric.
- galgebra.mv.norm2(A: Mv, hint: str = '0') Expr [source]
Equivalent to
Mv.norm2()
Returns the normsquared of multivector self, defined as the absolute value of the quadratic form at self.
norm2(A() returns a real SymPy expression, NOT a GAlgebra 0-vector. Whether numeric or symbolic, norm2(A) always represents a nonnegative number.
String values ‘+’, ‘-’, or ‘0’ of hint respectively determine whether the quadratic form, the absolute value of which is the norm squared, should be regarded as nonnegative, nonpositive, or of unknown sign, except when that quantity’s sign can be determined by other considerations, such as the metric being Euclidean.
- galgebra.mv.norm(A: Mv, hint: str = '0') Expr [source]
Equivalent to
Mv.norm()
Whether numeric nor symbolic, returned value is a real SymPy expression that necessarily represents a nonnegative number. Returned value is NOT a GAlgebra 0-vector.
String values ‘+’, ‘-’, or ‘0’ of hint respectively determine whether a symbolic self.norm2() expression should be regarded as nonnegative, nonpositive, or of unknown sign.
- galgebra.mv.mag2(A: Mv) Expr [source]
Equivalent to
Mv.mag2()
Returns the magnitude squared of multivector self, defined as the sum of the absolute values of the norm squareds of self’s grade parts.
Returned value is a real SymPy expression, NOT a GAlgebra 0-vector. Expression necesssarily represents a nonnegative number.
The magnitude squared differs from the normsquared of self when the metric is non-Euclidean.
- galgebra.mv.mag(A: Mv) Expr [source]
Equivalent to
Mv.mag()
Returns the magnitude of multivector self, defined as the square root of the magnitude squared.
The magnitude necessarily agrees with the norm only when the metric is Euclidean. Otherwise the magnitude is greater than or equal to the norm.
- galgebra.mv.rot(itheta: Mv, A: Mv, hint: str = '-') Mv [source]
Equivalent to
A.rotate_multivector(itheta, hint)
whereitheta
is the bi-vector blade defining the rotation. For the use ofhint
see the methodMv.rotate_multivector()
.
- galgebra.mv.refl(B: Mv, A: Mv) Mv [source]
Reflect multivector \(A\) in blade \(B\). Returns
\(\sum_{r}(-1)^{s(r+1)}B{\left < {A} \right >}_{r}B^{-1}\).
if \(B\) has grade \(s\). Equivalent to
Mv.reflect_in_blade()
- galgebra.mv.ccon(A: Mv) Mv [source]
Equivalent to :meth: Mv.ccon.
Returns Clifford conjugate of multivector self, i.e. returns the reverse of self’s grade involute.
Clifford conjugation is its own inverse operation.
- galgebra.mv.scalar(A: Mv) Expr [source]
Equivalent to
Mv.scalar()
- galgebra.mv.sp(A: Mv, B: Mv, switch='') Expr [source]
Equivalent to :meth: Mv.sp.
Returns scalar product of multivectors A and B.
Returns a real SymPy expression, not a GAlgebra 0-vector.
switch can be either ‘’ (the empty string) or ‘rev’. The latter causes left factor A to be reversed before its product with B is taken.