I have a large list of the following form
{{1, 2} -> -1, {1, 1} -> 1, {1, 2} -> -1, {1, 6} -> 1} and I want to combine all of the pairs x->yx->y that share the same xx value by adding up their yy values. For the above example I want to have
{{1, 2} -> -2, {1, 1} -> 1, {1, 6} -> 1} and I want to do it using patterns and ReplaceRepeatedReplaceRepeated command. I tried the following code:
{{1, 2} -> -1, {1, 1} -> 1, {1, 2} -> -1, {1, 6} -> 1} //. HoldPattern[{x_ -> y_, a___, x_ -> z_}] -> {x -> y + z, a} Can anybody tell me why above code is not working and how can I do it using rules?