# cirq.LinearDict¶

class cirq.LinearDict(terms: Optional[Mapping[TVector, Union[complex, float]]] = None, validator: Callable[TVector, bool] = <function LinearDict.<lambda>>)[source]

Represents linear combination of things.

LinearDict implements the basic linear algebraic operations of vector
addition and scalar multiplication for linear combinations of abstract
vectors. Keys represent the vectors, values represent their coefficients.
The only requirement on the keys is that they be hashable (i.e. are
immutable and implement hash and eq with equal objects hashing
to equal values).
A consequence of treating keys as opaque is that all relationships between
the keys other than equality are ignored. In particular, keys are allowed
to be linearly dependent.
__init__(terms: Optional[Mapping[TVector, Union[complex, float]]] = None, validator: Callable[TVector, bool] = <function LinearDict.<lambda>>) → None[source]

Initializes linear combination from a collection of terms.

Parameters
• terms – Mapping of abstract vectors to coefficients in the linear combination being initialized.

• validator – Optional predicate that determines whether a vector is valid or not. Dictionary and linear algebra operations that would lead to the inclusion of an invalid vector into the combination raise ValueError exception. By default all vectors are valid.