Pointwise addition of dictionaries¶
Provides function to add dictionaries pointwise with values in a common ring and to compute linear combinations
EXAMPLES:
sage: from sage.combinat.dict_addition import dict_addition
sage: D1 = { 0:1, 1:1 }; D2 = { 0:-1, 1:1 }
sage: dict_addition( [D1,D2] )
{1: 2}
-
sage.combinat.dict_addition.
dict_addition
(dict_iter)¶ Returns the pointwise addition of dictionaries with coefficients.
Parameters: dict_iter – iterator of dictionaries with values in a common ring. OUTPUT:
- a dictionary containing all keys of dictionaries in
dict_list
, with values being the sum of the values in the different dictionaries (keys with zero value are omitted)
EXAMPLES:
sage: from sage.combinat.dict_addition import dict_addition sage: D = { 0:1, 1:1 }; D {0: 1, 1: 1} sage: dict_addition( D for _ in range(5) ) {0: 5, 1: 5} sage: D1 = { 0:1, 1:1 }; D2 = { 0:-1, 1:1 } sage: dict_addition( [D1,D2] ) {1: 2}
- a dictionary containing all keys of dictionaries in
-
sage.combinat.dict_addition.
dict_linear_combination
(dict_factor_iter, factor_on_left=True)¶ Returns the pointwise addition of dictionaries with coefficients.
Parameters: - dict_factor_iter – iterator of pairs D, coeff, where - the D’s are dictionaries with values in a common ring - the coeff’s are coefficients in this ring
- factor_on_left (boolean; optional, default
True
) – if True, the coefficients are multiplied on the left, otherwise they are multiplied on the right
OUTPUT:
- a dictionary containing all keys of dictionaries in
dict_list
, with values being the sum of the values in the different dictionaries, each one first multiplied by the given factor (keys with zero value are omitted)
EXAMPLES:
sage: from sage.combinat.dict_addition import dict_linear_combination sage: D = { 0:1, 1:1 }; D {0: 1, 1: 1} sage: dict_linear_combination( (D,i) for i in range(5) ) {0: 10, 1: 10} sage: dict_linear_combination( [(D,1),(D,-1)] ) {}