qnet.algebra.core.indexed_operations module

Base classes for indexed operations (sums and products)

Summary

Classes:

IndexedSum Base class for indexed sums

__all__: IndexedSum

Reference

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

Bases: qnet.algebra.core.abstract_algebra.Operation

Base class for indexed sums

term
operands

Tuple of operands of the operation

args

Alias for operands

variables

List of the dummy (index) variable symbols

See also :property:`bound_symbols` for a set of the same symbols

bound_symbols

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

See also :property:`variables` for an ordered list of the same symbols

free_symbols

Set of all free symbols

kwargs

The dictionary of keyword-only arguments for the instantiation of the Expression

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.