pycommute.expression
Polynomial expressions involving quantum-mechanical operators and manipulations with them.
Index sequence
Indices is a wrapper around libcommute’s
dynamically-typed indices.
Note
Indices objects are not the same thing as Python tuples because
they follow a different ordering rule. Unlike the Python tuples, two
index sequences I1 and I2 always compare as I1 < I2 if
len(I1) < len(I2).
- class pycommute.expression.Indices
Mixed sequence of integer/string indices.
- __eq__(self: pycommute.expression.Indices, arg0: pycommute.expression.Indices) bool
- __getitem__(self: pycommute.expression.Indices, arg0: SupportsInt) int | str
Individual index access.
- __gt__(self: pycommute.expression.Indices, arg0: pycommute.expression.Indices) bool
- __init__(self: pycommute.expression.Indices, *args) None
Construct an index sequence from positional integer/string arguments.
- __iter__(self: pycommute.expression.Indices) collections.abc.Iterator[int | str]
- __len__(self: pycommute.expression.Indices) int
Index sequence length.
- __lt__(self: pycommute.expression.Indices, arg0: pycommute.expression.Indices) bool
- __ne__(self: pycommute.expression.Indices, arg0: pycommute.expression.Indices) bool
- __repr__(self: pycommute.expression.Indices) str
- property indices
Index sequence as a list of integers and strings.
Algebra ID constants
- expression.FERMION = -3
Fermionic algebra ID.
- expression.BOSON = -2
Bosonic algebra ID.
- expression.SPIN = -1
Spin algebra ID.
Algebra generator objects
The following classes wrap libcommute’s base class for algebra generators as well as its extensions for fermionic, bosonic and spin algebras.
- class pycommute.expression.Generator
Abstract algebra generator.
- __eq__(self: pycommute.expression.Generator, g2: pycommute.expression.Generator) bool
- __gt__(self: pycommute.expression.Generator, g2: pycommute.expression.Generator) bool
- __init__(self: pycommute.expression.Generator, arg0: pycommute.expression.Indices) None
- __lt__(self: pycommute.expression.Generator, g2: pycommute.expression.Generator) bool
- __ne__(self: pycommute.expression.Generator, g2: pycommute.expression.Generator) bool
- __repr__(self: pycommute.expression.Generator) str
String representation of the generator. This method can be overridden in subclasses.
- algebra_id(self: pycommute.expression.Generator) int
ID of the algebra this generator belongs to. This method must be overridden in subclasses.
- conj(self: pycommute.expression.Generator, f: pycommute.expression.LinearFunctionGen) None
Return the Hermitian conjugate of
selfas a linear function of generators viaf.This method can be overridden in subclasses. The default implementation assumes that the generator is Hermitian.
- equal(self: pycommute.expression.Generator, g: pycommute.expression.Generator) bool
Determine whether two generators
selfandgbelonging to the same algebra are equal.This method can be overridden in subclasses. The default implementation compares
Indicescarried by the generators.
- greater(self: pycommute.expression.Generator, g: pycommute.expression.Generator) bool
Determine whether two generators
selfandgbelonging to the same algebra satisfyself>g.This method can be overridden in subclasses. The default implementation compares
Indicescarried by the generators.
- less(self: pycommute.expression.Generator, g: pycommute.expression.Generator) bool
Determine whether two generators
selfandgbelonging to the same algebra satisfyself<g.This method can be overridden in subclasses. The default implementation compares
Indicescarried by the generators.
- reduce_power(self: pycommute.expression.Generator, power: SupportsInt, f: pycommute.expression.LinearFunctionGen) bool
Given a generator \(g_1\) =
selfand apower> 2, optionally apply a simplifying transformation \(g_1^\text{power} \mapsto f(g)\). If a simplification is actually possible,reduce_power()must returnTrueand write the linear function \(f(g)\) intof. Otherwise returnFalse.N.B. Simplifications for
power= 2 must be carried out bysimplify_prod().This method can be overridden in subclasses. The default implementation always returns
False.
- simplify_prod(self: pycommute.expression.Generator, g2: pycommute.expression.Generator, f: pycommute.expression.LinearFunctionGen) bool
Given a pair of generators \(g_1\) =
selfand \(g_2\) such that \(g_1 g_2\) is in the canonical order (\(g_1 \leq g_2\)), optionally apply a simplifying transformation \(g_1 g_2 \mapsto f(g)\). If a simplification is actually possible,simplify_prod()must returnTrueand write the linear function \(f(g)\) intof. Otherwise returnFalse.This method can be overridden in subclasses. The default implementation always returns
False.
- swap_with(self: pycommute.expression.Generator, g2: pycommute.expression.Generator, f: pycommute.expression.LinearFunctionGen) int | fractions.Fraction | float
Given a pair of generators \(g_1\) =
selfand \(g_2\) such that \(g_1 > g_2\),swap_with()must signal what transformation \(g_1 g_2 \mapsto c g_2 g_1 + f(g)\) should be applied to the product \(g_1 g_2\) to put it into the canonical order.swap_with()returns the constant \(c\) and writes the linear function \(f(g)\) intof. \(c\) is allowed to be zero.This method must be overridden in subclasses.
- property indices
Indices carried by this generator.
- class pycommute.expression.GeneratorFermion
Bases:
GeneratorGenerator of the fermionic algebra.
- __init__(self: pycommute.expression.GeneratorFermion, dagger: bool, indices: pycommute.expression.Indices) None
Construct a creation or annihilation fermionic operator with given indices.
- property dagger
Is this generator a creation operator?
- expression.make_fermion(dagger: bool, *args) pycommute.expression.GeneratorFermion
Make a creation or annihilation fermionic operator with indices passed as positional arguments.
- class pycommute.expression.GeneratorBoson
Bases:
GeneratorGenerator of the bosonic algebra.
- __init__(self: pycommute.expression.GeneratorBoson, dagger: bool, indices: pycommute.expression.Indices) None
Construct a creation or annihilation bosonic operator with given indices.
- property dagger
Is this generator a creation operator?
- expression.make_boson(dagger: bool, *args) pycommute.expression.GeneratorBoson
Make a creation or annihilation bosonic operator with indices passed as positional arguments.
- class pycommute.expression.SpinComponent(*values)
Enumeration: spin operator component, \(S_+\), \(S_-\) or \(S_z\).
- PLUS = 0
- MINUS = 1
- Z = 2
- class pycommute.expression.GeneratorSpin
Bases:
GeneratorGenerator of the spin algebra.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self:
pycommute.expression.GeneratorSpin, comp:pycommute.expression.SpinComponent, indices:pycommute.expression.Indices) -> None
Construct a spin-1/2 operator corresponding to a single spin component and carrying given indices.
- Parameters:
comp – Which spin component to construct, one of
SpinComponentvalues.indices – Index sequence of the spin component operator.
__init__(self:
pycommute.expression.GeneratorSpin, spin:typing.SupportsFloat, comp:pycommute.expression.SpinComponent, indices:pycommute.expression.Indices) -> None
Construct an operator for a general spin \(S\) corresponding to a single spin component and carrying given indices.
- Parameters:
spin – Integer or half-integer value of spin \(S\).
comp – Which spin component to construct, one of
SpinComponentvalues.indices – Index sequence of the spin component operator.
- property component
Whether this generator \(S_+\), \(S_-\) or \(S_z\)?
- property multiplicity
Multiplicity \(2S+1\) of the spin algebra this generator belongs to.
- property spin
Spin \(S\) of the algebra this generator belongs to.
- expression.make_spin(*args, **kwargs)
Overloaded function.
make_spin(comp:
pycommute.expression.SpinComponent, *args) ->pycommute.expression.GeneratorSpin
Make a spin-1/2 operator corresponding to a single spin component and carrying indices passed as positional arguments.
- Parameters:
comp – Which spin component to construct, one of
SpinComponentvalues.*args – Indices of the operator.
make_spin(spin:
typing.SupportsFloat, comp:pycommute.expression.SpinComponent, *args) ->pycommute.expression.GeneratorSpin
Make an operator for a general spin \(S\) corresponding to a single spin component and carrying indices passed as positional arguments.
- Parameters:
spin – Integer or half-integer value of spin \(S\).
comp – Which spin component to construct, one of
SpinComponentvalues.*args – Indices of the operator.
Linear combination of algebra generators
LinearFunctionGen represents a linear combination of algebra
generators plus a constant term. A new algebra can be defined by extending
the Generator class. Generator.swap_with() and related
methods overridden in the subclass must update terms of a
LinearFunctionGen object passed to them in order to specify the
commutation relations and simplification rules for the new algebra.
- class pycommute.expression.LinearFunctionGen
Linear combination of algebra generators \(g_1, \ldots, g_n\) plus a constant term,
\[f(g_1, \ldots, g_n) = c + c_1 g_1 + \ldots + c_n g_n.\]The coefficients \(c, c_1, \ldots, c_n\) can be of the type
int,fractions.Fractionorfloat.- property const_term
Constant term \(c\).
- property terms
List of pairs (tuples) of algebra generators and their respective coefficients,
\[(g_1, c_1), \ldots, (g_n, c_n).\]
- property vanishing
Is this linear function identically zero?
Monomial object
Monomial is a wrapper around libcommute’s
monomial object, i.e. an ordered product of
generators.
- class pycommute.expression.Monomial
Monomial: A product of algebra generators
- __contains__(self: pycommute.expression.Monomial, arg0: pycommute.expression.Generator) bool
- __copy__(self: pycommute.expression.Monomial) pycommute.expression.Monomial
- __deepcopy__(self: pycommute.expression.Monomial, memo: dict) pycommute.expression.Monomial
- __eq__(self: pycommute.expression.Monomial, arg0: pycommute.expression.Monomial) bool
Equality of monomials.
- __getitem__(*args, **kwargs)
Overloaded function.
__getitem__(self:
pycommute.expression.Monomial, arg0:typing.SupportsInt) ->pycommute.expression.Generator
Get a generator in the monomial by its position.
__getitem__(self:
pycommute.expression.Monomial, arg0: slice) ->pycommute.expression.Monomial
Get a slice of the monomial.
- __gt__(self: pycommute.expression.Monomial, arg0: pycommute.expression.Monomial) bool
Lexicographical greater-comparison to another monomial.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self:
pycommute.expression.Monomial) -> None
Construct an identity monomial (a product of zero generators).
__init__(self:
pycommute.expression.Monomial, arg0: collections.abc.Sequence[pycommute.expression.Generator]) -> None
Construct from a list of algebra generators.
- __iter__(self: pycommute.expression.Monomial) collections.abc.Iterator[pycommute.expression.Generator]
Returns an iterator to the sequence of algebra generators.
- __len__(self: pycommute.expression.Monomial) int
Number of generators in this monomial.
- __lt__(self: pycommute.expression.Monomial, arg0: pycommute.expression.Monomial) bool
Lexicographical less-comparison to another monomial.
- __mul__(*args, **kwargs)
Overloaded function.
__mul__(self:
pycommute.expression.Monomial, arg0:pycommute.expression.Generator) ->pycommute.expression.Monomial
Multiplication of the monomial by an algebra generator from the right.
__mul__(self:
pycommute.expression.Monomial, arg0:pycommute.expression.Monomial) ->pycommute.expression.Monomial
Multiplication of the monomial by another monomial from the right.
- __ne__(self: pycommute.expression.Monomial, arg0: pycommute.expression.Monomial) bool
Inequality of monomials.
- __repr__(self: pycommute.expression.Monomial) str
String representation of the monomial.
- __reverse__(self: pycommute.expression.Monomial) collections.abc.Iterator[pycommute.expression.Generator]
Returns a reverse iterator to the sequence of algebra generators.
- __rmul__(self: pycommute.expression.Monomial, arg0: pycommute.expression.Generator) pycommute.expression.Monomial
Multiplication of the monomial by an algebra generator from the left.
- swap_generators(self: pycommute.expression.Monomial, n1: SupportsInt, n2: SupportsInt) None
Swap two generators at given positions within the monomial.
- Parameters:
n1 – Position of the first generator to be swapped.
n2 – Position of the second generator to be swapped.
- property is_ordered
Is this monomial canonically ordered?
Expression objects
ExpressionR and ExpressionC represent libcommute’s
polynomial expression objects specialized for the real and
complex scalar types respectively.
- class pycommute.expression.ExpressionR
Polynomial in quantum-mechanical operators with real coefficients.
- __add__(*args, **kwargs)
Overloaded function.
__add__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
Addition of real polynomial expressions.
__add__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
Right addition of a real constant.
__add__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Addition of two polynomial expressions (real + complex).
__add__(self:
pycommute.expression.ExpressionR, arg0: complex) ->pycommute.expression.ExpressionC
Right addition of a complex constant.
- __copy__(self: pycommute.expression.ExpressionR) pycommute.expression.ExpressionR
- __deepcopy__(self: pycommute.expression.ExpressionR, memo: dict) pycommute.expression.ExpressionR
- __eq__(self: pycommute.expression.ExpressionR, arg0: pycommute.expression.ExpressionR) bool
Equality of two polynomial expressions.
- __iadd__(*args, **kwargs)
Overloaded function.
__iadd__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
In-place addition of a real polynomial expression.
__iadd__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
In-place addition of a real constant.
- __imul__(*args, **kwargs)
Overloaded function.
__imul__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
In-place multiplication by a real polynomial expression from the right.
__imul__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
In-place multiplication by a real constant.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self:
pycommute.expression.ExpressionR) -> None
Construct a zero expression.
__init__(self:
pycommute.expression.ExpressionR, x:typing.SupportsFloat) -> None
Construct a constant expression equal to \(x\).
- Parameters:
x – Constant \(x\).
__init__(self:
pycommute.expression.ExpressionR, x:typing.SupportsFloat, m:pycommute.expression.Monomial) -> None
Construct an expression with one monomial, \(x \cdot m\).
- Parameters:
x – Coefficient \(x\).
m – Monomial \(m\).
- __isub__(*args, **kwargs)
Overloaded function.
__isub__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
In-place subtraction of a real polynomial expression.
__isub__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
In-place subtraction of a real constant.
- __iter__(self: pycommute.expression.ExpressionR) collections.abc.Iterator[tuple[pycommute.expression.Monomial, float]]
Returns an iterator over monomial-coefficient pairs in the expression.
- __len__(self: pycommute.expression.ExpressionR) int
Number of monomials in this expression.
- __mul__(*args, **kwargs)
Overloaded function.
__mul__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
Multiplication of real polynomial expressions.
__mul__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
Right multiplication by a real constant.
__mul__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Multiplication of two polynomial expressions (real * complex).
__mul__(self:
pycommute.expression.ExpressionR, arg0: complex) ->pycommute.expression.ExpressionC
Right multiplication by a complex constant.
- __ne__(self: pycommute.expression.ExpressionR, arg0: pycommute.expression.ExpressionR) bool
Inequality of two polynomial expressions.
- __neg__(self: pycommute.expression.ExpressionR) pycommute.expression.ExpressionR
Unary minus.
- __radd__(*args, **kwargs)
Overloaded function.
__radd__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
Left addition of a real constant.
__radd__(self:
pycommute.expression.ExpressionR, arg0: complex) ->pycommute.expression.ExpressionC
Left addition of a complex constant.
- __repr__(self: pycommute.expression.ExpressionR) str
String representation of the polynomial expression.
- __rmul__(*args, **kwargs)
Overloaded function.
__rmul__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
Left multiplication by a real constant.
__rmul__(self:
pycommute.expression.ExpressionR, arg0: complex) ->pycommute.expression.ExpressionC
Left multiplication by a complex constant.
- __rsub__(*args, **kwargs)
Overloaded function.
__rsub__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
Subtraction from a real constant.
__rsub__(self:
pycommute.expression.ExpressionR, arg0: complex) ->pycommute.expression.ExpressionC
Subtraction from a complex constant.
- __sub__(*args, **kwargs)
Overloaded function.
__sub__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
Subtraction of real polynomial expressions.
__sub__(self:
pycommute.expression.ExpressionR, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionR
Subtraction of a real constant.
__sub__(self:
pycommute.expression.ExpressionR, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Subtraction of two polynomial expressions (real - complex).
__sub__(self:
pycommute.expression.ExpressionR, arg0: complex) ->pycommute.expression.ExpressionC
Subtraction of a complex constant.
- clear(self: pycommute.expression.ExpressionR) None
Reset expression to zero.
- class pycommute.expression.ExpressionC
Polynomial in quantum-mechanical operators with complex coefficients.
- __add__(*args, **kwargs)
Overloaded function.
__add__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Addition of complex polynomial expressions.
__add__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
Right addition of a complex constant.
__add__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionC
Addition of two polynomial expressions (complex + real).
__add__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
Right addition of a real constant.
- __copy__(self: pycommute.expression.ExpressionC) pycommute.expression.ExpressionC
- __deepcopy__(self: pycommute.expression.ExpressionC, memo: dict) pycommute.expression.ExpressionC
- __eq__(self: pycommute.expression.ExpressionC, arg0: pycommute.expression.ExpressionC) bool
Equality of two polynomial expressions.
- __iadd__(*args, **kwargs)
Overloaded function.
__iadd__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
In-place addition of a complex polynomial expression.
__iadd__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
In-place addition of a complex constant.
__iadd__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionC
In-place addition of a real polynomial expression.
__iadd__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
In-place addition of a real constant.
- __imul__(*args, **kwargs)
Overloaded function.
__imul__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
In-place multiplication by a complex polynomial expression from the right.
__imul__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
In-place multiplication by a complex constant.
__imul__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionC
In-place multiplication by a real polynomial expression.
__imul__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
In-place multiplication by a real constant.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self:
pycommute.expression.ExpressionC) -> None
Construct a zero expression.
__init__(self:
pycommute.expression.ExpressionC, x: complex) -> None
Construct a constant expression equal to \(x\).
- Parameters:
x – Constant \(x\).
__init__(self:
pycommute.expression.ExpressionC, x: complex, m:pycommute.expression.Monomial) -> None
Construct an expression with one monomial, \(x \cdot m\).
- Parameters:
x – Coefficient \(x\).
m – Monomial \(m\).
__init__(self:
pycommute.expression.ExpressionC, expr:pycommute.expression.ExpressionR) -> None
Construct from a real expression by complexifying its coefficients.
- __isub__(*args, **kwargs)
Overloaded function.
__isub__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
In-place subtraction of a complex polynomial expression.
__isub__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
In-place subtraction of a complex constant.
__isub__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionC
In-place subtraction of a real polynomial expression.
__isub__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
In-place subtraction of a real constant.
- __iter__(self: pycommute.expression.ExpressionC) collections.abc.Iterator[tuple[pycommute.expression.Monomial, complex]]
Returns an iterator over monomial-coefficient pairs in the expression.
- __len__(self: pycommute.expression.ExpressionC) int
Number of monomials in this expression.
- __mul__(*args, **kwargs)
Overloaded function.
__mul__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Multiplication of complex polynomial expressions.
__mul__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
Right multiplication by a complex constant.
__mul__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionC
Multiplication of two polynomial expressions (complex * real).
__mul__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
Right multiplication by a real constant.
- __ne__(self: pycommute.expression.ExpressionC, arg0: pycommute.expression.ExpressionC) bool
Inequality of two polynomial expressions.
- __neg__(self: pycommute.expression.ExpressionC) pycommute.expression.ExpressionC
Unary minus.
- __radd__(*args, **kwargs)
Overloaded function.
__radd__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
Left addition of a complex constant.
__radd__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
Left addition of a real constant.
- __repr__(self: pycommute.expression.ExpressionC) str
String representation of the polynomial expression.
- __rmul__(*args, **kwargs)
Overloaded function.
__rmul__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
Left multiplication by a complex constant.
__rmul__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
Left multiplication by a real constant.
- __rsub__(*args, **kwargs)
Overloaded function.
__rsub__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
Subtraction from a complex constant.
__rsub__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
Subtraction from a real constant.
- __sub__(*args, **kwargs)
Overloaded function.
__sub__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Subtraction of complex polynomial expressions.
__sub__(self:
pycommute.expression.ExpressionC, arg0: complex) ->pycommute.expression.ExpressionC
Subtraction of a complex constant.
__sub__(self:
pycommute.expression.ExpressionC, arg0:pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionC
Subtraction of two polynomial expressions (complex - real).
__sub__(self:
pycommute.expression.ExpressionC, arg0:typing.SupportsFloat) ->pycommute.expression.ExpressionC
Subtraction of a real constant.
- clear(self: pycommute.expression.ExpressionC) None
Reset expression to zero.
- expression.conj(*args, **kwargs)
Overloaded function.
conj(expr:
pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
Hermitian conjugate of an expression.
- Parameters:
expr – Expression to conjugate.
conj(expr:
pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Hermitian conjugate of an expression.
- Parameters:
expr – Expression to conjugate.
- expression.transform(*args, **kwargs)
Overloaded function.
transform(expr:
pycommute.expression.ExpressionR, f: collections.abc.Callable[[pycommute.expression.Monomial,typing.SupportsFloat], float]) ->pycommute.expression.ExpressionR
Apply a given function to all monomial/coefficient pairs and replace the coefficients with values returned by the function. Zero return values will result in respective monomials being discarded.
- Parameters:
transform(expr:
pycommute.expression.ExpressionC, f: collections.abc.Callable[[pycommute.expression.Monomial, complex], complex]) ->pycommute.expression.ExpressionC
Apply a given function to all monomial/coefficient pairs and replace the coefficients with values returned by the function. Zero return values will result in respective monomials being discarded.
- Parameters:
transform(expr:
pycommute.expression.ExpressionR, f: collections.abc.Callable[[pycommute.expression.Monomial,typing.SupportsFloat], complex]) ->pycommute.expression.ExpressionC
Apply a given function to all monomial/coefficient pairs and replace the coefficients with values returned by the function. Zero return values will result in respective monomials being discarded.
- Parameters:
transform(expr:
pycommute.expression.ExpressionC, f: collections.abc.Callable[[pycommute.expression.Monomial, complex], float]) ->pycommute.expression.ExpressionR
Apply a given function to all monomial/coefficient pairs and replace the coefficients with values returned by the function. Zero return values will result in respective monomials being discarded.
Expression factory functions
These are wrapped libcommute’s factory functions for polynomial expressions with dynamically typed indices.
- expression.c_dag(*args) pycommute.expression.ExpressionR
Returns a fermionic creation operator with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
- expression.c(*args) pycommute.expression.ExpressionR
Returns a fermionic annihilation operator with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
- expression.n(*args) pycommute.expression.ExpressionR
Returns a fermionic particle number operator with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
- expression.a_dag(*args) pycommute.expression.ExpressionR
Returns a bosonic creation operator with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
- expression.a(*args) pycommute.expression.ExpressionR
Returns a bosonic annihilation operator with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
- expression.S_p(*args, **kwargs)
Overloaded function.
S_p(*args) ->
pycommute.expression.ExpressionR
Returns a spin-1/2 raising operator \(S_+\) with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
S_p(*args, **kwargs) ->
pycommute.expression.ExpressionR
Returns a general spin raising operator \(S_+\) with indices passed as positional arguments.
- Parameters:
spin – Spin \(S\) (keyword-only).
*args – Indices of the operator.
- expression.S_m(*args, **kwargs)
Overloaded function.
S_m(*args) ->
pycommute.expression.ExpressionR
Returns a spin-1/2 lowering operator \(S_-\) with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
S_m(*args, **kwargs) ->
pycommute.expression.ExpressionR
Returns a general spin lowering operator \(S_-\) with indices passed as positional arguments.
- Parameters:
spin – Spin \(S\) (keyword-only).
*args – Indices of the operator.
- expression.S_x(*args, **kwargs)
Overloaded function.
S_x(*args) ->
pycommute.expression.ExpressionC
Returns a spin-1/2 x-projection operator \(S_x\) with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
S_x(*args, **kwargs) ->
pycommute.expression.ExpressionC
Returns a general spin \(S\) x-projection operator \(S_x\) with indices passed as positional arguments.
- Parameters:
spin – Spin \(S\) (keyword-only).
*args – Indices of the operator.
- expression.S_y(*args, **kwargs)
Overloaded function.
S_y(*args) ->
pycommute.expression.ExpressionC
Returns a spin-1/2 y-projection operator \(S_y\) with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
S_y(*args, **kwargs) ->
pycommute.expression.ExpressionC
Returns a general spin \(S\) y-projection operator \(S_y\) with indices passed as positional arguments.
- Parameters:
spin – Spin \(S\) (keyword-only).
*args – Indices of the operator.
- expression.S_z(*args, **kwargs)
Overloaded function.
S_z(*args) ->
pycommute.expression.ExpressionR
Returns a spin-1/2 z-projection operator \(S_z\) with indices passed as positional arguments.
- Parameters:
*args – Indices of the operator.
S_z(*args, **kwargs) ->
pycommute.expression.ExpressionR
Returns a general spin \(S\) z-projection operator \(S_z\) with indices passed as positional arguments.
- Parameters:
spin – Spin \(S\) (keyword-only).
*args – Indices of the operator.
- expression.make_complex(expr: pycommute.expression.ExpressionR) pycommute.expression.ExpressionC
Make a complex expression out of a real one.
- Parameters:
expr – Real expression to be complexified.
Hermitian conjugate placeholder
HC is the Python analog of libcommute’s
Hermitian conjugate placeholder.
- class pycommute.expression.HC
A placeholder type that adds/subtracts the Hermitian conjugate to/from an expression. There is a module-level constant of this type called
hc, which allows to mimic the \(\pm H.c.\) notation in expressions.- __radd__(*args, **kwargs)
Overloaded function.
__radd__(self: pycommute.expression.HC, arg0:
pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
Add the Hermitian conjugate of a real expression.
__radd__(self: pycommute.expression.HC, arg0:
pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Add the Hermitian conjugate of a complex expression.
- __rsub__(*args, **kwargs)
Overloaded function.
__rsub__(self: pycommute.expression.HC, arg0:
pycommute.expression.ExpressionR) ->pycommute.expression.ExpressionR
Subtract the Hermitian conjugate of a real expression.
__rsub__(self: pycommute.expression.HC, arg0:
pycommute.expression.ExpressionC) ->pycommute.expression.ExpressionC
Subtract the Hermitian conjugate of a complex expression.
- expression.hc = <pycommute.expression.HC object>