Let’s return to simpler math for this post; middle school math to be exact. J has some unique features that make it an excellent tool for teaching division, fractions, and decimals.
Most calculators and computer programs have historically made no provision for rational numbers, aka fractions. This included APL, and Dr. Iverson thought it was a serious shortcoming that needed to be remedied. I did a few brief searches and discovered a pocket calculator, the Sharp EL348RB, that can convert decimals and fractions. The iTunes store has a calculator type app, Fraction Calculator, for their iphone with iOS 3. It calculates with fractions. I haven’t used either one, but these are single line devices incapable of doing, say, this:
The above is Dr. Iverson’s fraction addition table using the (r) rational operator as in one half = 1r2. The table was published in his Math for Layman, pg 2. He was pleased that he could add this to J. Note that the command line is above the box, which is created by the table command. You might like to try making tables using multiplication (*) and subtraction (-).
(Note on the table function. I used 1+i.12 for the multiplication tables in prior posts. The “i” in that case stands for integer. A fraction is not an integer, so the i function can’t be used. The table function provides another way. The table also produces boxes. J provides multiple roads to your destination.)
So, getting back to the actual division and fraction operators, I discussed Matrix Divide (%.) before I discussed plain old division (%) so let’s begin with ordinary division. To do ordinary division in J, you type the problem as you say it. For example, “What is four divided by two?” You would enter the problem that way:
4 % 2
444444 % 222
444444 % 2222
Which brings up the question of decimals. You use divide (%) if you want your answers in decimals.
2 % 4
2 % 8
Note that J always puts a zero in front of the decimal point if the number is less than 1. So should you. Also note that the division operator will only give you decimals.
So, How do you calculate fractions in J? As in the above fraction addition table, you use the (r) for rational operator instead of the (%) division operator. Let’s see how the (r) operator works in J. We will start with a fraction that has not been simplified:
Notice that J automatically simplifies the fraction. It will also simplify the fraction to a whole number:
In the following two examples, we see that when the division yields a whole number, the answers from both the r and the % operators are the same:
444444 % 222
In J, the r operator will also simplify the fraction to a whole number. But it will not simplify a fraction to a mixed number:
In this case, you will have to use the division operator:
7 % 2
Then, figure out the answer on your own (3.5 = 3 and 1/2.) But, the r operator will simplify the fraction if possible:
And if we take the answer and substitute the % division operator for the
r rational operator, we get the same answer with either set of numbers:
20202 % 101
444444 % 2222
You can use J to do the math, or to test your answers if you are learning math. If you need a book on basic arithmetic, my recommendation is Gerard W. Kelly Short Cut Math. You might want W. Michael Kelley’s Humongous Book of Pre-Algebra Problems if your need is junior high math.