MultiVectors Module Reference

Module Attributes

multivectors._

The scalar basis multivector (a 0-blade). Usage:

>>> from multivectors import _
>>> 2 * _
(2.0)
multivectors.x
multivectors.y
multivectors.z
multivectors.w

Basis vectors for the first four dimensions. Additional bases can be swizzled on the module:

>>> from multivectors import x, y, z, xyz
>>> x * y * z == xyz
True

The MultiVector class

class multivectors.MultiVector(termdict: Dict[Tuple[int, ...], float])

A linear combination of geometric products of basis vectors.

The bare constructor is not meant for regular use. Use module swizzling or the factory from_terms() instead.

Basis vector names can be swizzled on instances:

>>> from multivectors import x, y, z
>>> (x + y).x
1.0
>>> (x*y + z).xy
1.0
>>> (x + y).e3
0.0

And indices can be combined:

>>> (x + y) % 0
1.0
>>> (x*y + z) % (0, 1)
1.0
>>> (x + y) % 2
0.0
property grade: Optional[int]

The grade of this blade.

Returns

The number of different bases this blade consists of, or None if this multivector is not a blade (one term).

Examples

>>> from multivectors import x, y, z
>>> (x + y).grade # not a blade
>>> (z * 2 + z).grade
1
>>> (x*y*z).grade
3
property terms: Tuple[MultiVector, ...]

Get a sequence of blades comprising this multivector.

Examples

>>> from multivectors import x, y, z, w
>>> (x + y).terms
((1.0 * x), (1.0 * y))
>>> ((x + y) * (z + w)).terms
((1.0 * x*z), (1.0 * x*w), (1.0 * y*z), (1.0 * y*w))
classmethod from_terms(*terms: Union[float, MultiVector]) MultiVector

Create a multivector by summing a sequence of terms.

Parameters

*terms – The terms. If you have an iterable of terms, use (e.g.) from_terms(*terms)

Returns

A multivector.

Examples

>>> from multivectors import x, y, z
>>> MultiVector.from_terms(x, y)
(1.0 * x + 1.0 * y)
>>> MultiVector.from_terms()
(0.0)
>>> MultiVector.from_terms(z)
(1.0 * z)
>>> MultiVector.from_terms(2 * x, x)
(3.0 * x)
classmethod scalar(num) MultiVector

Create a MultiVector representing a scalar.

Parameters

num – Any object that can be float()-d.

Returns

A multivector with only a scalar part of num.

Examples

>>> from multivectors import MultiVector
>>> MultiVector.scalar('0')
(0.0)
>>> MultiVector.scalar('1.2')
(1.2)
__getattr__(name: str) float

Support basis name swizzling.

__getitem__(grades: Union[int, Iterable[int], slice]) MultiVector

The choose operator - returns the sum of all blades of grade k.

Parameters

grades – The grade(s) to choose.

Examples

>>> from multivectors import x, y, z
>>> (1 + 2*x + 3*y + 4*x*y)[1]
(2.0 * x + 3.0 * y)
>>> (1 + 2 + 3*x + 4*x*y + 5*y*z)[2]
(4.0 * x*y + 5.0 * y*z)
>>> (1 + 2 + 3*x + 4*x*y + 5*y*z)[0]
(3.0)
>>> (1 + 2 + 3*x + 4*x*y + 5*y*z).choose(0)
(3.0)
>>> (1 + 2*x + 3*x*y)[:2]
(1.0 + 2.0 * x)
>>> (1 + 2*x + 3*x*y)[1:]
(2.0 * x + 3.0 * x*y)
choose(grades: Union[int, Iterable[int], slice]) MultiVector

The choose operator - returns the sum of all blades of grade k.

Parameters

grades – The grade(s) to choose.

Examples

>>> from multivectors import x, y, z
>>> (1 + 2*x + 3*y + 4*x*y)[1]
(2.0 * x + 3.0 * y)
>>> (1 + 2 + 3*x + 4*x*y + 5*y*z)[2]
(4.0 * x*y + 5.0 * y*z)
>>> (1 + 2 + 3*x + 4*x*y + 5*y*z)[0]
(3.0)
>>> (1 + 2 + 3*x + 4*x*y + 5*y*z).choose(0)
(3.0)
>>> (1 + 2*x + 3*x*y)[:2]
(1.0 + 2.0 * x)
>>> (1 + 2*x + 3*x*y)[1:]
(2.0 * x + 3.0 * x*y)
__repr__() str

Return a representation of this multivector. Depending on the global namespace, this may be eval()-able.

Examples

>>> from multivectors import x, y, z, w
>>> repr(x)
'(1.0 * x)'
>>> repr(x + y)
'(1.0 * x + 1.0 * y)'
>>> repr(y*z - x*w)
'(-1.0 * x*w + 1.0 * y*z)'
__str__() str

Return a representation of this multivector suited for showing.

Examples

>>> from multivectors import x, y, z, w
>>> str(x)
'1.00x'
>>> str(x + y)
'(1.00x + 1.00y)'
>>> str(y*z - x*w)
'(-1.00xw + 1.00yz)'
>>> print(1 + x + x*y)
(1.00 + 1.00x + 1.00xy)
__format__(spec: str) str

Return a representation of this multivector suited for formatting.

Parameters

spec – The format spec (forwarded to the underlying :class:`float`s)

Examples

>>> from multivectors import x, y, z, w
>>> f'{x:.3f}'
'1.000x'
>>> V = x + 2 * y + z
>>> '{:.3f}'.format(V)
'(1.000x + 2.000y + 1.000z)'
>>> V = y*z - x*w
>>> f'{V:.1f}'
'(-1.0xw + 1.0yz)'
__eq__(other: Union[float, MultiVector]) bool

Compare equality of two objects.

Returns

True if all terms of this multivector are equal to the other; True if this multivector is scalar and equals the other; or False for all other cases or types.

Examples

>>> from multivectors import x, y
>>> x + y == y + x
True
>>> x + 2*y == 2*x + y
False
__ne__(other: Union[float, MultiVector]) bool

Compare inequality of two objects.

Returns

False if all terms of this multivector are equal to the other; False if this multivector is scalar and equals the other; or True for all other cases or types.

Examples

>>> from multivectors import x, y
>>> x + y != y + x
False
>>> x + 2*y != 2*x + y
True
__lt__(other: float) bool

Compare this blade less than an object.

Returns

True if this is a scalar blade less than the scalar; False if this is a scalar blade not less than the scalar; or NotImplemented for all other types.

Examples

>>> from multivectors import _, x
>>> _ * 1 < 2
True
>>> _ * 2 < 1
False
>>> x * 1 < 2
Traceback (most recent call last):
    ...
TypeError: '<' not supported between instances of 'MultiVector' and 'int'
__gt__(other: float) bool

Compare this blade greater than an object.

Returns

True if this is a scalar blade greater than the scalar; False if this is a scalar blade not greater than the scalar; or NotImplemented for all other types.

Examples

>>> from multivectors import _, x
>>> _ * 1 > 2
False
>>> _ * 2 > 1
True
>>> x * 1 > 2
Traceback (most recent call last):
    ...
TypeError: '>' not supported between instances of 'MultiVector' and 'int'
__le__(other: float) bool

Compare this blade less than or equal to an object.

Returns

True if this is a scalar blade less than or equal to the scalar; False if this is a scalar blade greater than the scalar; or NotImplemented for all other types.

Examples

>>> from multivectors import _, x
>>> _ * 1 <= 2
True
>>> _ * 2 <= 2
True
>>> _ * 2 <= 1
False
>>> x * 1 <= 2
Traceback (most recent call last):
    ...
TypeError: '<=' not supported between instances of 'MultiVector' and 'int'
__ge__(other: float) bool

Compare this blade greater than or equal to an object.

Returns

True if this is a scalar blade greater than or equal to the scalar; False if this is a scalar blade less than the scalar; or NotImplemented for all other types.

Examples

>>> from multivectors import _, x
>>> _ * 1 >= 2
False
>>> _ * 2 >= 2
True
>>> _ * 2 >= 1
True
>>> x * 1 >= 2
Traceback (most recent call last):
    ...
TypeError: '>=' not supported between instances of 'MultiVector' and 'int'
__add__(other: Union[float, MultiVector]) MultiVector

Add a multivector and another object.

Examples

>>> from multivectors import x, y, z, w
>>> (x + z) + (y + w)
(1.0 * x + 1.0 * y + 1.0 * z + 1.0 * w)
>>> (x + z) + y
(1.0 * x + 1.0 * y + 1.0 * z)
>>> (x + y) + 1
(1.0 + 1.0 * x + 1.0 * y)
__radd__(other: float) MultiVector

Support adding multivectors on the right side of objects.

Examples

>>> from multivectors import x, y, z
>>> 1 + (x + z)
(1.0 + 1.0 * x + 1.0 * z)
>>> x + (y + z)
(1.0 * x + 1.0 * y + 1.0 * z)
__sub__(other: Union[float, MultiVector]) MultiVector

Subtracting is adding the negation.

Examples

>>> from multivectors import x, y, z, w
>>> (x + z) - (y + w)
(1.0 * x + -1.0 * y + 1.0 * z + -1.0 * w)
>>> (x + z) - y
(1.0 * x + -1.0 * y + 1.0 * z)
__rsub__(other: float) MultiVector

Support subtracting multivectors from objects.

Examples

>>> from multivectors import x, y, z, w
>>> 1 - (x + z)
(1.0 + -1.0 * x + -1.0 * z)
>>> x - (y + z)
(1.0 * x + -1.0 * y + -1.0 * z)
__mul__(other: Union[float, MultiVector]) MultiVector

Multiply a multivector and another object.

Returns

(a + b) * (c + d) = a*c + a*d + b*c + b*d for multivectors (a + b) and (c + d).

Returns

(a + b) * v = a*v + b*v for multivector (a + b) and scalar v.

Examples

>>> from multivectors import x, y, z, w
>>> (x + y) * (z + w)
(1.0 * x*z + 1.0 * x*w + 1.0 * y*z + 1.0 * y*w)
>>> (x + y) * 3
(3.0 * x + 3.0 * y)
>>> (x + y) * x
(1.0 + -1.0 * x*y)
__rmul__(other: float) MultiVector

Support multiplying multivectors on the right side of scalars.

Examples

>>> from multivectors import x, y
>>> 3 * (x + y)
(3.0 * x + 3.0 * y)
>>> y * (x + y)
(1.0 + -1.0 * x*y)
__matmul__(other: Union[float, MultiVector]) MultiVector

Get the inner (dot) product of two objects.

Returns

u @ v = (u * v)[abs(u.grade - v.grade)] when grade is defined.

Returns

(a + b) @ (c + d) = a@c + a@d + b@c + b@d for multivectors (a + b) and (c + d)

Returns

(a + b) @ v = a@v + b@v for multivector (a + b) and scalar v

Examples

>>> from multivectors import x, y, z
>>> (2*x + 3*y) @ (4*x + 5*y)
(23.0)
>>> (2*x*y).dot(3*y*z)
(0.0)
>>> (x + y).inner(3)
(3.0 * x + 3.0 * y)
>>> (x + y) @ x
(1.0)
dot(other: Union[float, MultiVector]) MultiVector

Get the inner (dot) product of two objects.

Returns

u @ v = (u * v)[abs(u.grade - v.grade)] when grade is defined.

Returns

(a + b) @ (c + d) = a@c + a@d + b@c + b@d for multivectors (a + b) and (c + d)

Returns

(a + b) @ v = a@v + b@v for multivector (a + b) and scalar v

Examples

>>> from multivectors import x, y, z
>>> (2*x + 3*y) @ (4*x + 5*y)
(23.0)
>>> (2*x*y).dot(3*y*z)
(0.0)
>>> (x + y).inner(3)
(3.0 * x + 3.0 * y)
>>> (x + y) @ x
(1.0)
inner(other: Union[float, MultiVector]) MultiVector

Get the inner (dot) product of two objects.

Returns

u @ v = (u * v)[abs(u.grade - v.grade)] when grade is defined.

Returns

(a + b) @ (c + d) = a@c + a@d + b@c + b@d for multivectors (a + b) and (c + d)

Returns

(a + b) @ v = a@v + b@v for multivector (a + b) and scalar v

Examples

>>> from multivectors import x, y, z
>>> (2*x + 3*y) @ (4*x + 5*y)
(23.0)
>>> (2*x*y).dot(3*y*z)
(0.0)
>>> (x + y).inner(3)
(3.0 * x + 3.0 * y)
>>> (x + y) @ x
(1.0)
__rmatmul__(other: float) MultiVector

Support dotting multivectors on the right hand side.

Returns

v @ (a + b) = v@a + v@b for multivector (a + b) and scalar v

Examples

>>> from multivectors import x, y
>>> 3 @ (x + y)
(3.0 * x + 3.0 * y)
>>> x @ (x + y)
(1.0)
__truediv__(other: Union[float, MultiVector]) MultiVector

Divide two objects.

Returns

(a + b) / v = a/v + b/v

Examples

>>> from multivectors import x, y
>>> (6*x + 9*y) / 3
(2.0 * x + 3.0 * y)
>>> (6*x + 9*y) / (3*x)
(2.0 + -3.0 * x*y)
__rtruediv__(other: float) MultiVector

Divide a scalar by a multivector. Only defined for blades.

Examples

>>> from multivectors import x, y
>>> 1 / x
(1.0 * x)
>>> 2 / (4 * x*y)
(-0.5 * x*y)
__mod__(idxs: Union[int, Iterable[int], slice]) float

Support index swizzling.

Examples

>>> from multivectors import x, y
>>> (x + y) % 0
1.0
>>> v = 1 + 2*y + 3*x*y
>>> v % ()
1.0
>>> v % 1
2.0
>>> v % (0, 1)
3.0
>>> v % 2
0.0
__pow__(other: int) MultiVector

A multivector raised to an integer power.

V ** n = V * V * V * ... * V, n times. V ** -n = 1 / (V ** n)

Examples

>>> from multivectors import x, y
>>> (x + y) ** 3
(2.0 * x + 2.0 * y)
>>> (2 * x*y) ** -5
(-0.03125 * x*y)
__rpow__(other: float) MultiVector

A real number raised to a multivector power.

x ** V = e ** ln(x ** V) = e ** (V ln x)

Examples

>>> from multivectors import x, y
>>> round(2 ** (x + y), 2)
(1.52 + 0.81 * x + 0.81 * y)
exp() MultiVector

e raised to this multivector power.

\[e^V = \exp(V) = \sum_{n=0}^{\infty} \frac{V^n}{n!}\]

Examples

>>> from math import pi, sqrt
>>> from multivectors import x, y
>>> # 45-degree rotation through xy-plane
>>> # results in (1+xy)/sqrt(2)
>>> (pi/4 * x*y).exp() * sqrt(2)
(1.0 + 1.0 * x*y)
>>> round((pi * x*y).exp(), 14)
(-1.0)
__xor__(other: Union[float, MultiVector]) MultiVector

Get the outer (wedge) product of two objects.

Warning

Operator precedence puts ^ after +! Make sure to put outer products in parentheses, like this: u * v == u @ v + (u ^ v)

Returns

u ^ v = (u * v)[u.grade + v.grade] when grade is defined

Returns

(a + b) ^ (c + d) = (a^c) + (a^d) + (b^c) + (b^d) for multivector (a + b) and (c + d)

Returns

(a + b) ^ v = (a^v) + (b^v) for multivector (a + b) and scalar v

Examples

>>> from multivectors import x, y, z
>>> (2*x + 3*y) ^ (4*x + 5*y)
(-2.0 * x*y)
>>> (2*x*y).wedge(3*y*z)
(0.0)
>>> (x + y).outer(3)
(3.0 * x + 3.0 * y)
>>> (x + y) ^ x
(-1.0 * x*y)
wedge(other: Union[float, MultiVector]) MultiVector

Get the outer (wedge) product of two objects.

Warning

Operator precedence puts ^ after +! Make sure to put outer products in parentheses, like this: u * v == u @ v + (u ^ v)

Returns

u ^ v = (u * v)[u.grade + v.grade] when grade is defined

Returns

(a + b) ^ (c + d) = (a^c) + (a^d) + (b^c) + (b^d) for multivector (a + b) and (c + d)

Returns

(a + b) ^ v = (a^v) + (b^v) for multivector (a + b) and scalar v

Examples

>>> from multivectors import x, y, z
>>> (2*x + 3*y) ^ (4*x + 5*y)
(-2.0 * x*y)
>>> (2*x*y).wedge(3*y*z)
(0.0)
>>> (x + y).outer(3)
(3.0 * x + 3.0 * y)
>>> (x + y) ^ x
(-1.0 * x*y)
outer(other: Union[float, MultiVector]) MultiVector

Get the outer (wedge) product of two objects.

Warning

Operator precedence puts ^ after +! Make sure to put outer products in parentheses, like this: u * v == u @ v + (u ^ v)

Returns

u ^ v = (u * v)[u.grade + v.grade] when grade is defined

Returns

(a + b) ^ (c + d) = (a^c) + (a^d) + (b^c) + (b^d) for multivector (a + b) and (c + d)

Returns

(a + b) ^ v = (a^v) + (b^v) for multivector (a + b) and scalar v

Examples

>>> from multivectors import x, y, z
>>> (2*x + 3*y) ^ (4*x + 5*y)
(-2.0 * x*y)
>>> (2*x*y).wedge(3*y*z)
(0.0)
>>> (x + y).outer(3)
(3.0 * x + 3.0 * y)
>>> (x + y) ^ x
(-1.0 * x*y)
__rxor__(other: float) MultiVector

Support wedging multivectors on the right hand side.

Returns

v ^ (a + b) = (v^a) + (v^b) for multivector (a + b) and simple v

Examples

>>> from multivectors import x, y
>>> 3 ^ (x + y)
(3.0 * x + 3.0 * y)
>>> x ^ (x + y)
(1.0 * x*y)
__neg__() MultiVector

The negation of a multivector is the negation of all its terms.

Examples

>>> from multivectors import x, y, z
>>> -(2*x + 3*y*z)
(-2.0 * x + -3.0 * y*z)
__pos__() MultiVector

A normalized multivector is one scaled down by its magnitude.

Examples

>>> from multivectors import x, y, z, w
>>> +(x + y + z + w)
(0.5 * x + 0.5 * y + 0.5 * z + 0.5 * w)
>>> round((x + y).normalize(), 3)
(0.707 * x + 0.707 * y)
normalize() MultiVector

A normalized multivector is one scaled down by its magnitude.

Examples

>>> from multivectors import x, y, z, w
>>> +(x + y + z + w)
(0.5 * x + 0.5 * y + 0.5 * z + 0.5 * w)
>>> round((x + y).normalize(), 3)
(0.707 * x + 0.707 * y)
__abs__() float

The magnitude of a multivector is the square root of the sum of the squares of its terms.

Examples

>>> from multivectors import x, y, z, w
>>> abs(x + y + z + w)
2.0
>>> (2 ** 1.5 * x + 2 ** 1.5 * y).magnitude()
4.0
magnitude() float

The magnitude of a multivector is the square root of the sum of the squares of its terms.

Examples

>>> from multivectors import x, y, z, w
>>> abs(x + y + z + w)
2.0
>>> (2 ** 1.5 * x + 2 ** 1.5 * y).magnitude()
4.0
__invert__() MultiVector

The conjugate of a multivector is the negation of all terms besides the real component.

Examples

>>> from multivectors import x, y
>>> ~(1 + 2*x + 3*x*y)
(1.0 + -2.0 * x + -3.0 * x*y)
>>> (2 + 3*y).conjugate()
(2.0 + -3.0 * y)
conjugate() MultiVector

The conjugate of a multivector is the negation of all terms besides the real component.

Examples

>>> from multivectors import x, y
>>> ~(1 + 2*x + 3*x*y)
(1.0 + -2.0 * x + -3.0 * x*y)
>>> (2 + 3*y).conjugate()
(2.0 + -3.0 * y)
__complex__() complex

Convert a scalar to a complex number.

Examples

>>> from multivectors import _, x
>>> complex(2 * _)
(2+0j)
>>> complex(3 * x)
Traceback (most recent call last):
    ...
TypeError: cannot convert non-scalar blade (3.0 * x) to complex
__int__() int

Convert a scalar to an integer.

Examples

>>> from multivectors import _, x
>>> int(2 * _)
2
>>> int(3 * x)
Traceback (most recent call last):
    ...
TypeError: cannot convert non-scalar blade (3.0 * x) to int
__float__() float

Convert a scalar to a float.

Examples

>>> from multivectors import _, x
>>> float(2 * _)
2.0
>>> float(3 * x)
Traceback (most recent call last):
    ...
TypeError: cannot convert non-scalar blade (3.0 * x) to float
__round__(ndigits: Optional[int] = None) MultiVector

Round the scalars of each component term of a multivector.

Examples

>>> from multivectors import x, y
>>> round(1.7 * x + 1.2 * y)
(2.0 * x + 1.0 * y)
>>> round(0.15 * x + 0.05 * y, 1)
(0.1 * x + 0.1 * y)
__trunc__() MultiVector

Truncate the scalars of each component term of a multivector.

Examples

>>> import math
>>> from multivectors import x, y
>>> math.trunc(1.7 * x + 1.2 * y)
(1.0 * x + 1.0 * y)
>>> math.trunc(-1.7 * x - 1.2 * y)
(-1.0 * x + -1.0 * y)
__floor__() MultiVector

Floor the scalars of each component term of a multivector.

Examples

>>> import math
>>> from multivectors import x, y
>>> math.floor(1.7 * x + 1.2 * y)
(1.0 * x + 1.0 * y)
>>> math.floor(-1.7 * x - 1.2 * y)
(-2.0 * x + -2.0 * y)
__ceil__() MultiVector

Ceiling the scalars of each component term of a multivector.

Examples

>>> import math
>>> from multivectors import x, y
>>> math.ceil(1.7 * x + 1.2 * y)
(2.0 * x + 2.0 * y)
>>> math.ceil(-1.7 * x - 1.2 * y)
(-1.0 * x + -1.0 * y)
rotate(angle: float, plane: MultiVector) MultiVector

Rotate this multivector by angle in rads around the blade plane.

Parameters
  • angle – Angle to rotate by, in radians.

  • plane – Blade representing basis plane to rotate through.

Returns

Rotated multivector.

Examples

>>> from math import radians
>>> from multivectors import x, y, z, w
>>> round((3*x + 2*y + 4*z).rotate(
...     radians(90), x*y), 2)
(-2.0 * x + 3.0 * y + 4.0 * z)
>>> round((3*x + 2*y + 4*z + 5*w).rotate(
...     radians(90), x*y*z), 2)
(3.0 * x + 2.0 * y + 4.0 * z + -5.0 * x*y*z*w)
angle_to(other: MultiVector) float

Get the angle between this multivector and another.

Examples

>>> from math import degrees
>>> from multivectors import x, y, z, w
>>> math.degrees((x + y).angle_to(x - y))
90.0
>>> round(math.degrees((x + y + z + w).angle_to(x - y - z - w)), 2)
120.0
__hash__ = None

Helper Functions

These functions are not really meant for exporting, but are included for completeness.

multivectors.merge(arr: List[int], left: List[int], right: List[int]) int

Perform a merge of sorted lists and count the swaps.

Parameters
  • arr – The list to write into.

  • left – The left sorted list.

  • right – The right sorted list.

Returns

The number of swaps made when merging.

multivectors.count_swaps(arr: List[int], copy: bool = True) int

Count the number of swaps needed to sort a list.

Parameters
  • arr – The list to sort.

  • copy – If True, (the default) don’t modify the original list.

Returns

The number of swaps made when sorting the list.

Examples

>>> count_swaps([1, 3, 2, 5, 4])
2
>>> count_swaps([3, 2, 1])
3
multivectors.names_to_idxs(name: str, raise_on_invalid_chars: bool = False) List[int]

Convert swizzled basis vector names into generalized basis indices.

Parameters
  • name – The names to convert.

  • raise_on_invalid_chars – If True (default False), raise AttributeError if any characters appear in the name that are invalid in a basis name.

Returns

A list of basis indexes that the name represents.

Raises

AttributeError – If characters invalid for a basis name appear, and raise_on_invalid_chars is True.

Examples

>>> names_to_idxs('xyw')
[0, 1, 3]
>>> names_to_idxs('e_1e2_z')
[0, 1, 2]
>>> names_to_idxs('_')
[]
multivectors.idxs_to_idxs(idxs: Union[int, Iterable[int], slice]) List[int]

Convert multiple possible ways to specify multiple indices.

This is intended to be given the argument to MultiVector indexing: V[0] would call idxs_to_idxs(0), V[0, 1] would call idxs_to_idxs((0, 1)), and V[0:1] would call idxs_to_idxs(slice(0, 1, None))

Parameters

idxs – The indexes to convert. This can be an integer, for just that index; an iterable of integers, for those indexes directly; or a slice, for the indexes the slice represents.

Returns

A list of basis indexes, converted from the argument.

Examples

>>> idxs_to_idxs(slice(None, 5, None))
[0, 1, 2, 3, 4]
>>> idxs_to_idxs((1, 3, 4))
[1, 3, 4]
>>> idxs_to_idxs(1)
[1]
multivectors.idxs_to_names(idxs: Union[int, Iterable[int], slice], sep: str = '') str

Convert indices to a swizzled name combination.

Parameters
  • idxs – The basis index(es), as accepted by idxs_to_idxs().

  • sep – The separator to use between the basis vector names.

Returns

The swizzled names.

Examples

>>> idxs_to_names(slice(None, 5, None))
'e1e2e3e4e5'
>>> idxs_to_names((0, 1, 3))
'xyw'
>>> idxs_to_names(2)
'z'
>>> idxs_to_names((0, 2, 3), sep='*')
'x*z*w'
multivectors.condense_bases(bases: Tuple[int, ...], scalar: float = 1.0) Tuple[Tuple[int, ...], float]

Normalize a sequence of bases, modifying the scalar as necessary.

Parameters
  • bases – The tuple of basis indices.

  • scalar – Real number that will scale the resulting bases.

Returns

A 2-tuple of normalized bases and the modified scalar.

Examples

>>> condense_bases((1, 1, 2, 1, 2), 2.0)
((1,), -2.0)
>>> condense_bases((1, 2, 1, 2), 1.5)
((), -1.5)
>>> condense_bases((2, 1, 3, 2, 3, 3), 1.0)
((1, 3), 1.0)