I am looking for a correct implement of dot product using mpmath, but they give me different results, which I don't understand why.
sum = mp.mpf(0.)
for i in range(n):
sum += mp.mpf(x[i]) * mp.mpf(y[i]) # 1st method
# sum += mp.mpf(str(x[i])) * mp.mpf(str(y[i])) # 2nd mehtod
I am using them to solve ill-conditioned dot products and the two give very different results. This is very important because I am comparing them with my another accurate dot product algorithm, which agrees with the 1st method , and disagree with the 2nd method. So I want to understand if I should trust the answer from the 1st.