1. ## Interesting Question

Hi all,

I've got a question which I didn't know how to answer, and where else to post it.

I program pretty much everyday and recently, my 5 year-old nephew has been sitting with me and asking questions (pretty simple ones really, but it's great that he's interested at such a young age!).

Yesterday as I was writing a very simple addition program for him to think about, he asked a question which I couldn't answer, so I thought I could ask the guys here if they can think of an answer that I could tell him.

I said that the computer takes the two variables and adds them together, so he asked "So, how do you know that the computer is right then?"

Can anyone think of a way in which I could explain to him without going in to too much detail, or giving the answer "it just is" please?

Thanks for the help,

SM

2. The reliability of the computer has been tested by many other people, and made in such a way as to (almost) always be right. I would stress the fact that the computer is made as a machine that listens to instructions, and has been made to specification so that it always works when built properly, just like any other machine he uses. Once people that make computers are sure it's right, then they sell them.

Naturally, I'd simplify it a little bit more, but the concept of the computer being built to spec as a machine is important since he's smart to ask the question about reliability. If the computer isn't consistent, there is no reason to use it as we do.

3. > so he asked "So, how do you know that the computer is right then?"
Perhaps by showing that the computer isn't right all the time, and the programmer has a big part to play in getting the "right" answer.

Code:
```#include <stdlib.h>
int main ( void ) {
unsigned char u1, u2, u3;
signed char   s1, s2, s3;
u1 = u2 = 100;
u3 = u1 + u2;
s1 = s2 = 100;
s3 = s1 + s2;
printf("%d\n", u3 );
printf("%d\n", s3 );
return 0;
}

\$ gcc foo.c
\$ ./a.exe
200
-56```

4. Tell him there are thousands of miniature Indians inside the computer, and that when the computer needs to add numbers together, the Indians add them up on their fingers. They can count really, really fast, and you know they're never wrong, because they're Indians.

At least this is what my dad told me...

5. There is not a simple way to explain why the computer is right. The actual reason the computer can calculate values is actually quite complex and involves voltages and circuits.

http://www.flexbeta.net/main/article...showarticle=15

So any voltage over a set amount in a computer system will results in a 1 and any voltage below that will result in a 0. Transistors are the main component that represent the one's and zero's since they are either on or off. Transistors come in many flavors but that is not critical to the discussion here. We know an unsigned char as 8 bits which comprises what we know as the byte. So 1 byte really resolves to 8 separate voltages being interpreted high or low to create 1's or 0's. These 1's and 0's or highs and lows can have other operations performed on them as well. Once this has been resolved the computer then interprets the final value into a character we can see on screen. Even numbers are characters as it relates to this discussion but they are merely for the end user to understand what is going on and not vital to the operation of the underlying circuits. If the computer did not interpret the final values into characters we can see and understand, the calculations and operations would still work but we would have know way of knowing they did without having some type of measuring device to determine the output.

Now how does the computer know how we want to interpret the data? How does it know that we want the value 65 instead of a capital A? That is accomplished through data types. This is why when you open an EXE file inside of Notepad you get nothing but gibberish. Notepad is expecting to interpret the values into characters but what it is reading are actually hexadecimal opcode values that resolve into machine language instructions. Since Notepad is not a disassembler, it uses the hexadecimal value as a lookup index into the character table or into the Windows character table. A disassembler would know how to interpret the opcodes into the english-like mnuemonics like mov rep add, etc. A disassembler would also know based on the platform and CPU in the system how to correctly interpret which values are literal and which ones are opcodes. The disassembler programmer gets this information right from the Intel or AMD tech refs which explain in great detail how the instruction opcodes work, what to expect when and where, and how to correctly display the result on screen.

You have probably experienced this when your printf went nutso and started printing randomly from memory due to a wild pointer or a lack of a null terminator. The only way printf() knows how to interpret the data is by the tokens and flags you use in the printf() format string. If your data type does not match the format you specified, you get gibberish because it is not translated correctly for the given data type.

But in the end it comes down to voltages of high's and low's on transistors in the CPU. The actual instruction implementation of add, subtract, multiply, divide, etc in the CPU is quite complex and gets heavily into electrical engineering which is not my forte.

6. I'd go with Salem's answer.

7. I'd go with MacGyver's answer. The computer is a machine. It does the things it does in the same way every time. People have tried out the computer and have checked that it is right when adding numbers, so you know it will always be right when adding.

Salem's answer involves integer ranges, and I think that's too complex. Besides, it doesn't answer the question.

8. Computers do break down. Usually when they break nothing works. Anything will eventually wear out or break. I always thought that the computer was built to catch any errors that might happen for some odd reason or another. When we write code we often handle such exceptions. It is just with programs, we can usually handle it gracefully and the computer doesn't start to smoke. With hardware your computer just beeps unless it is a fatal exception and then your computer will just sit there with a blank screen until you buy a new one or fix it. Usually protective circuits are built in to chips.

If you google for "when computer chips fail", you will get a lot of interesting articles about what happens when they do.
http://www.thefreelibrary.com/Sick+c...y...-a04030992

If you go further you might get stuff about the old TV show. Whatever happend to Poncho?

I would just tell him that the computer is right as long as he can verify the answer the computer provided is correct. He will be a math wiz trying to prove the computer wrong.

actually that might not be the best idea since we already have built in rounding errors due to the limitations of the data representation

9. Originally Posted by Rashakil Fol
They can count really, really fast, and you know they're never wrong, because they're Indians.
Well... that depends, sometimes the Big Indians have fights with the smaller ones and then all hell breaks loose.

10. 01 00 00 00 is little indian format
00 00 00 01 is big indian format

11. Salem's answer involves integer ranges, and I think that's too complex. Besides, it doesn't answer the question.
I was never so much for the coding part, but rather the fact that he mentions that you can't be sure that the computer adds correctly, and therefore, in essence, the programmer has to convince himself that the output is expected.

Even with an operation as trivial as addition, the computer is no replacement for the human brain. Only the programmer can know what is right and what is wrong.

12. Originally Posted by Salem
01 00 00 00 is little indian format
00 00 00 01 is big indian format
They seem so far away from one another.

13. Originally Posted by Happy_Reaper
you can't be sure that the computer adds correctly, and therefore, in essence, the programmer has to convince himself that the output is expected.
But that's misleading. I think the original question was really whether the computer could make basic mistakes like adding 1 and 1 and getting 3. It was a 5-year-old asking the question.

The programmer can do only so much. He can check that no overflow will occur, but for the actual calculation he has to trust the CPU. What will he do? assert() that a+b == a+b?

14. To be honest I'd frankly tell him to try it and see if the computer gets it wrong. And if that doesn't convince him, to tell him to keep trying until he either finds the computer making a mistake, or is convinced it won't make a mistake.

15. Originally Posted by Swordsman
I said that the computer takes the two variables and adds them together, so he asked "So, how do you know that the computer is right then?"

Can anyone think of a way in which I could explain to him without going in to too much detail, or giving the answer "it just is" please?
Tell him you don't know it's right. See Ken Thompson's Turing Award lecture.