qalgebra.core.indexed_operations module¶
Base classes for indexed operations (sums and products)
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 anIndexedSum
object, ranges can be assumed to be a tuple.
-
property
term
¶ The term of the sum.
-
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 itsdoit()
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 completelymax_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()
. SeeExpression.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 aranges
attribute)Each index symbol is primed until it does not match any index symbol in others.
-
classmethod