qalgebra.core.indexed_operations module

Base classes for indexed operations (sums and products)

Summary

Classes:

IndexedSum

Base class for indexed sums.

__all__: IndexedSum

Reference

class qalgebra.core.indexed_operations.IndexedSum(term, *, ranges)[source]

Bases: qalgebra.core.abstract_algebra.Operation

Base class for indexed sums.

classmethod create(term, *, ranges)[source]

Instantiate the indexed sum while applying simplification rules.

The ranges parameter should be a tuple, but for convenience, we also accept a single IndexRangeBase object, which will be converted to a single-element tuple. Note that when applying rules for the creation of an IndexedSum object, ranges can be assumed to be a tuple.

property term

The term of the sum.

property operands

Alias for args.

property args

Single-element tuple containing term.

property kwargs

Dictionary of keyword arguments (ranges).

property variables

List of the dummy (index) variable symbols.

See also bound_symbols for a set of the same symbols

property bound_symbols

Set of bound variables, i.e. the index variable symbols.

See also variables for an ordered list of the same symbols

property free_symbols

Set of all free symbols.

property terms

Iterator over the terms of the sum.

Yield from the (possibly) infinite list of terms of the indexed sum, if the sum was written out explicitly. Each yielded term in an instance of Expression

doit(classes=None, recursive=True, indices=None, max_terms=None, **kwargs)[source]

Write out the indexed sum explicitly.

If classes is None or IndexedSum is in classes, (partially) write out the indexed sum in to an explicit sum of terms. If recursive is True, write out each of the new sum’s summands by calling its doit() method.

Parameters
  • classes (None or list) – see Expression.doit()

  • recursive (bool) – see Expression.doit()

  • indices (list) – List of IdxSym indices for which the sum should be expanded. If indices is a subset of the indices over which the sum runs, it will be partially expanded. If not given, expand the sum completely

  • max_terms (int) – Number of terms after which to truncate the sum. This is particularly useful for infinite sums. If not given, expand all terms of the sum. Cannot be combined with indices

  • kwargs – keyword arguments for recursive calls to doit(). See Expression.doit()

make_disjunct_indices(*others)[source]

Return a copy with modified indices to ensure disjunct indices with others.

Each element in others may be an index symbol (IdxSym), a index-range object (IndexRangeBase) or list of index-range objects, or an indexed operation (something with a ranges attribute)

Each index symbol is primed until it does not match any index symbol in others.