basics

This submodule implements the most basic objects used throughout the package, ranging from Union and Complex numbers to customisable indices via CustomIndex and IntIndex. The latter then have to be tracked for custom Block implementations by use of the decorators @indices or @defaultIndices.

dim

Specifies the dimensions assumed in spacetime. Any change may require some adjustment of rotPlanes as well as any Block transformation properties.

Type:

int

rotPlanes

Spacetime indices associated to the different rotational planes.

Type:

tuple[tuple[sptIdx,sptIdx]]

class Complex(re: int | Fraction, im: int | Fraction = 0)

Bases: object

Rudimentary implementation of a rational-number-valued complex number.

Parameters:
  • re (int|Fraction) – Real part of the complex number.

  • im (int|Fraction, optional) – Imaginary part of the complex number, defaults to 0.

abs2() int | Fraction

Computes z*conj(z) of the complex number z.

Returns:

Absolute value squared of the current complex number.

Return type:

int|Fraction

conj()

Complex conjugation.

Returns:

Complex conjugate of the current complex number.

Return type:

Complex

phase()

Assuming the complex number to be purely real or purely imaginary, this function returns the sign and (for a purely imaginary number) an imaginary unit.

Returns:

Sign and any overall imaginary unit.

Return type:

Complex

Raises:

AssertionError – If number is not purely real or purely imaginary.

enum CustomIndex(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Custom-labelled indices.

Allows the definition of indices with custom string-valued labels. Uses Python Enum as underlying object to assign integer-values to those labels.

Parameters:
  • value (str) – The name of the new CustomIndex (Enum) to create.

  • names (list[str]) – The string-values to be used for labelling the custom indices.

enum IntIndex(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

Represents an integer-valued index, directly inherited from IntEnum without modification. Allows to define a range of values allowed for the indices.

class Union

Bases: object

Collection of elements x with an associated label str(x) assumed to be a unique identifier. Based on this label, adding a new element is vetoed if the label is already present.

add(x)

Adds element x to the collection if not already present according to its string-representation.

Parameters:

x (object) – Element to be added.

Returns:

Returns whether the element x has been added or vetoed due to already being present.

Return type:

bool

defaultIndices(cls)

Assumes the default behaviour for indices, i.e., the custom Block.__init__ is expected to have as arguments all the indices plus one called factor referring to the overall factor. The arguments belonging to indices must be named according to the class-member used to store the indices and must be type-hinted using the explicit type for each index.

Parameters:

cls (type) – Block implementations to be assigned default index conventions.

Returns:

The initial Block implementation but with indices assigned.

Return type:

type

indices(suffix: str | None, **kwargs: dict[str, type])

Sets the class attributes

cls.__indexType__ # tuple[type] referring to the type of the index
cls.__indexName__ # tuple[str]  referring to the index label
cls.__suffix__    # str         representation of indices etc.

Those are necessary to turn custom Block implementations into regular expressions. suffix is expected to carry as many %s as there are indices.

Parameters:
  • suffix (str|) – String representation of the trailing indices etc. used during calls to Block.__str__ as well as parsing from string representation via regular expressions. If None, the default form is chosen for __suffix__.

  • kwargs (dict[str,type]) – Collection of member-names of the current Block implementation referring to indices and their associated type. From Python 3.10 onwards dictionaries have a frozen order. Make sure to use an ordering of the indices that matches the arguments in the function signature.

Returns:

Handler acting on the actual class type.

Return type:

function

Raises:

AssertionError – If the number of %s in suffix does not match the number of indices.

massDim(md: int | Fraction)

Allows to assign a non-zero mass dimension to an instance of Block through use of a decorator @massDim(…) in front of the class implementation. Mass-dimensions are expected to be non-negative integers. If you want to deviate from this, one may rescale all other mass-dimensions to restore overall integer-valuedness.

Parameters:

md (int) – Mass-dimension that should be assigned to the current implementation of Block.

Returns:

cls – The initial Block implementation but with a mass-dimension set.

Return type:

type

Raises:

AssertionError – If the chosen mass-dimension is not a non-negative integer.

enum sptIdx(*values)

Bases: IntIndex

Valid values are as follows:

w = <sptIdx.w: 0>
x = <sptIdx.x: 1>
y = <sptIdx.y: 2>
z = <sptIdx.z: 3>