1. If 6 Was 9Jimi Hendrix 1967: A Computational Puzzle
Pay no attention to that man behind the curtain.
--The Wizard of Oz
We look at a simple Ox program that poses a puzzle about how computers do math. The answer to the puzzle must wait for a later chapter, but the puzzle may motivate you to learn about how computers works before trusting them with your own research.

Does $10x={\sum}_{i=1}^{10}\ x = x+x+\cdots+x$?
08-If6was9.ox
 1:    #include "oxstd.h"
 2:    main() {
 3:       decl x;
 4:       x = 0.25;
 5:       print( "Is 2.5=10*(0.25)? ");
 6:    //           0 1 2 3 4 5 6 7 8 9   check that there are 10 x's 
 7:       if (2.5== x+x+x+x+x+x+x+x+x+x)
 8:            println("Yes");
 9:       else
10:            println("No");
11:       x = 0.1;
12:       print( "Is 1.0=10*(0.10)?  ");
13:       if (1.0== x+x+x+x+x+x+x+x+x+x )
14:            println("Yes");
15:       else
16:            println("No");
17:       }
The program does something simple twice.
A number is assigned to a variable, x.
Then $10x$ is computed and compared to the value of adding x to itself 10 times.
This is done first for x=0.1 and then x=0.25.
The program prints out Yes or No based on the comparison of the two expressions.
Of course, in symbolic mathematics the results are identical to each other. But these operations are being carried out on a computer using digital mathematics not symbolic mathematics. The output when it is run is:
Is 2.5=10*(0.25)? Yes
Is 1.0=10*(0.10)? No
You are supposed to be surprised by this output. Please stop and be surprised for a second. I will wait

If you can explain the output you might read the next few chapters quickly. If you cannot explain the output, then as a student of economics you might thinking, Perhaps I cannot trust Ox to do arithmetic. After all, if you cannot rely on adding x to itself 10 times always being the same as 10x, for all values x, then how can we rely on it to, say, find a consumption bundle at which marginal utility equals the slope of the budget line?
The Pentium BugThe famous case of a real problem with computer arithmetic is the Intel Pentium Bug where about once every 9 billion divisions were incorrect.
Is this a flaw in Ox? A misunderstanding of the code? Or something deeper? If you use Stata or Matlab or Python you can verify that they will produce the same puzzling output.
Stata has a 10x 'problem'
. scalar x = 0.25
. di 2.5==x+x+x+x+x+x+x+x+x+x
1
. sca x = 0.1
. di 1.0==x+x+x+x+x+x+x+x+x+x
0
The outputs 1 and 0 are equivalent to yes and no.
Symbolic MathMathematica and Maple are designed to carry out symbolic operations, so this question would not apply to them, at least when they are in symbolic mode.)

This is an inherent feature of numerical math, and it illustrates a danger in using a programming language naively. However, once you understand this issue it is easy to avoid. The puzzle is due to a subtle feature of rational numbers. This is a curiosity but not ultimately a major issue in programming. It is trotted out now to motivate you to be a bit curious and a bit wary about what is happening when you use the computer to do math. Knowing how and why this happens will not make you a great economist, but it is a lesson along the way towards doing economics on the computer.

Do It AgainSteely Dan 1972: You can run this program to try different values of x:
09-If6was9reprise.ox
 1:    #include "oxstd.h"                                                  
 2:    main() {
 3:       decl x,x10;
 4:       println("\n At ? type a decimal number x and 10x then hit ENTER.\n",
 5:       		   "Example:\n? 2 20\n\nEnter 0 0 to exit");
 6:       do {
 7:       	scan("\n? %f %f",&x,&x10);
 8:    	if (x==0) break;
 9:    	print("Is ",x10," = 10(",x,")?\n",
10:    		x10==x+x+x+x+x+x+x+x+x+x ? "Yes!"
11:    								 : "No!",
12:    		"\n---------------");
13:    	} while (TRUE);
14:       }
15:       
This program does more than 08-If6was9.ox and in fewer lines. It uses an iterative statement (do { } while()) to repeat a statement (or block of statements) more than once, which eliminates the need to have almost duplicate lines. And it uses the conditional statement A ? B : C to check a condition (A) and return different values (B and C) depending on whether the condition is true or false.