## Question-Sum!!

For the discussion of math. Duh.

Moderators: gmalivuk, Moderators General, Prelates

mathmari
Posts: 81
Joined: Sat Apr 27, 2013 11:58 pm UTC

### Question-Sum!!

Hello !! I noticed,by writing a program in c,that,calculating a sum backwards gives a better approximation of the real value of the sum than calculating it forwards..Why does this happen???

Dopefish
Posts: 854
Joined: Sun Sep 20, 2009 5:46 am UTC
Location: The Well of Wishes

### Re: Question-Sum!!

What do you mean?

Order of the sum as in "double x = 5.3+4.7;" is giving you a different number than "double x = 4.7+5.3;"?

It might be worthwhile to post an example of the code that's giving odd results.

(Also, I suspect this is gonna end up being more of a coding type question than math, with an answer either being an issue with how numbers are represented under-the-hood or an outright coding error, rather than an unusual aspect of math itself at play.)

alessandro95
Posts: 109
Joined: Wed Apr 24, 2013 1:33 am UTC

### Re: Question-Sum!!

It is probably related to the floating point representation of reals but that should happen only on some particular sums, can you show us exactly which sum(s) are you speaking about?
The primary reason Bourbaki stopped writing books was the realization that Lang was one single person.

elasto
Posts: 3588
Joined: Mon May 10, 2010 1:53 am UTC

### Re: Question-Sum!!

If you are trying to add a wide range of fixed-precision numbers together, it's better to start with the small ones and finish with the big: Crudely speaking, adding the small ones together gives them a chance to become big, and so add to the big numbers correctly - whereas starting big and then adding small, the small ones will just get ignored.

See a thread like this for how to add numbers together with perfect precision: http://stackoverflow.com/questions/3941 ... nt-numbers

mathmari
Posts: 81
Joined: Sat Apr 27, 2013 11:58 pm UTC

### Re: Question-Sum!!

alessandro95 wrote:It is probably related to the floating point representation of reals but that should happen only on some particular sums, can you show us exactly which sum(s) are you speaking about?

The sum I am referring to is: Σ_{k=1}^{n}{1/k^2}.
Why is the approximation better at the backward sum in this case?

ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

### Re: Question-Sum!!

mathmari wrote:The sum I am referring to is: Σ_{k=1}^{n}{1/k^2}.
Why is the approximation better at the backward sum in this case?
He was probably asking you to post code snippets that give different results when you sum the same numbers in different order.
He/Him/His/Alex
God damn these electric sex pants!

elasto
Posts: 3588
Joined: Mon May 10, 2010 1:53 am UTC

### Re: Question-Sum!!

mathmari wrote:The sum I am referring to is: Σ_{k=1}^{n}{1/k^2}.
Why is the approximation better at the backward sum in this case?

Because going backwards adds small numbers before big numbers (see my previous post).

Btw: Two threads, both posted on the same day, both querying why the same series sums differently forwards to backwards? Homework? viewtopic.php?f=17&t=106157#p3487968

gmalivuk
GNU Terry Pratchett
Posts: 26566
Joined: Wed Feb 28, 2007 6:02 pm UTC
Location: Here and There
Contact:

### Re: Question-Sum!!

Yeah, this looks like it's a question about something brought up in that other thread, which means any further discussion of it can happen in that other thread as well.
Unless stated otherwise, I do not care whether a statement, by itself, constitutes a persuasive political argument. I care whether it's true.
---
If this post has math that doesn't work for you, use TeX the World for Firefox or Chrome

(he/him/his)