Given a vector v, I want to keep track of the sum of its elements in a variable sum_v. Each element i of the vector v is a dot product of a weight vector w_i with other vectors d_i. So, every time d_i changes, so does v. I have been updating sum_v by changing it according to the change in v_i whenever d_i changes. Unfortunately, small numerical instabilities quickly add up.
What efficient techniques can I use to prevent this?
Edit: Right now, my algorithm takes constant time to update sum_v whenever d_i changes. I'd like to stay below log(n) where n is the length of v.