XML Has Totally Failed ... On The Web
Norman Walsh: [...] six, nearly seven, years after the introduction of XHTML as a standard, XML has totally failed to replace “vernacular” HTML on the web.
JNI, Systen.unloadLibrary(), @Native(dll=foo, function=bar), ...
Dear Java people,
I understand that everybody is busy right now with new and exciting Java language features like closures and continuations and module systems and that Sun people are also busy with Open Sourcing pieces of (but not the whole) Java SE and ME before year's end and I'm really happy about all these developments.
But before you go off to the deep end and spend years debating, reviewing, testing, and releasing all these wonderful features, which I'm sure will draw more developers to the Java platform, could somebody please take a few minutes and take a look at my modest Java feature requests:
It has to do with JNI, the most elaborate and comprehensive native code interface I've ever seen in popular programming languages. It gets the job done (if you have the resources) but it's a pain to program with. And it is sometimes considered a performance bottleneck, what with all the locking and copying when a variable crosses the JNI boundary.
The first thing that I would like to have is a System.unloadLibrary() call to balance out the System.loadLibrary() call that has been present in the Java language from the beginning. This would make writing unloadable plug-ins that uses native code easier.
The second thing I would like to have is a @Native annotation that would direct the runtime system to generate JNI wrappers automatically. Come to think about it, had annotations been available in the Java language from the beginning, there probably wouldn't be a native keyword at all. The more I think about it, the more I think something like the following would make sense:
@Native(dll=foo,function=bar) public void bar();
The C/C++ stuff that people write after doing javah are boring, repetitive, tricky, and hard to get right. If the Java runtime can automatically generate the stuff from the annotation, that would bring about a productivity boost to the entire Java scene. Not only don't Java people have to write tedious code just to use native library functionality, they also don't have reinvent the wheel in Java because using a wheel written in C/C++ is so hard.
Talking about using natively available features, what's up with the HTML widget in the JDK. The last time I checked, it's HTML 3.2 and could not render even Yahoo.com right. Can we remove it from the JDK and bring in a native widget that uses the latest natively available HTML widget on the platform?
Dan Troesser: JSF and ASP.NET Side By Side
Dan Troesser is this month's OCI Java lunch speaker. He'll be talking about something that I've been interested in but haven't has a chance to get into deeply: JSF and ASP.NET
First person is Dan now.
We are going to talk about ASP.NET and compare it with JSF. I have been learning about JSF for the past year and a half. I have heard people talking about ASP.NET as something that's similar to JSF. So I investigated ASP.NET myself. I also looked into NetBeans 5.5 Beta. If you haven't looked at NetBeans, you should.
I'm just going to demo some stuff.
Dan has installed NetBeans 5.5 Beta 2 and GlassFish, the Sun Java EE server in the demo machine. It also have MS SQL Server Express and Visual Web Developer Express.
Dan is starting up the SQL Server service now. And it is started now.
Dan is bringing up the Microsoft SQL Server tool, showing the data that is prepopulated: some inventory data.
Dan is startign up Visual Studio 2005 now.
I got a free copy of VS 2005 from a Microsoft event for free last year.
From VS 2005, Dan is creating a website: Shopping. Just a couple of clicks.
With ASP.NET, they try to get you to do stuff in the GUI designer and hide the code. You can get at the code, you they want you to use the GUI.
Dan drags a grid view onto the form, and maps it to data. You create a data source for each component on the form.
Now Dan hit Control-F5 to run it. And the data showed up.
If I wanted to edit the data, I can go back to the design view of the form to "enable paging", "enable sorting", and "enable editing", "enable deleting." Unfortunately, we can't enable deleting from the GUI.
Now I can sort, edit a row and delete a row.
I a few steps, I had just created a simple app that does simple editing.
I can also format the columns.
I do have to turn HTML encoding off. That was listed as an ASP.NET issue.
The next thing I want to do is to create a page that allows me to insert a new column.
Dan drags a details view control onto the form and set up a data source. When generate the data source, Dan uses an advanced feature that has a check box that says "generate INSERT ..."
Then Dan enabled enserting on the control, and made the default mode to be inserting.
A Control-F5 and the page showed up.
Dan drags a hyper link on to one of the pages.
I wish using the hyper link is easier.
We also want to enable an event in the details view, onItemInsert and hook it up with a method.
Dan then added the method to the .cs file of the page.
I'm going to call Server.Transfer() to transfer the control to the other page.
Dan hit a snag upon running this page and resorted to using a pre-build version of the demo.
Now I can edit, I can delete items.
That's just a simple little idea of how you can do thing in Visual Studio.
Now I'm going to switch to NetBeans.
Dan starts NetBeans 5.5 Beta 2. It's turning on modules now.
The release candidate works pretty good now. When I installed the SQL Server JDBC driver, I have to install it into the proper "domain".
I'm going to start a new project. I'm creating an enterprise project.
I don't really need an EJB module, just want to create the web application.
We have some configuration files. It actually created two projects, an enterprise project and a war project. The configuration files doesn't contain much.
I want to enable JSF. With JSF, everything is within a "f:view" tag. For the most part, it's a code centric approach. The JSF project has a simple little start page.
Now I want to create some database connections. I create "entities from databases".
Dan picks the tables and the columns from some wizard screens.
I selected the inventory table. I want to create a persistence unit. I choose the TopLink. I haven't tried anything else.
Dan shows us the data bound classes that's created for us. It's a JPA annotated POJO class. NetBeans also warns us that one of our names is a SQL-92 keyword.
Dan now creates JSP pages from a wizard.
Dan starts the GlassFish application server.
Dan shows the pages in IE.
I can select each item, edit it. I can delete things. I can add a new inventory item. And so forth.
So we are able to create a view of this database table pretty easily.
Now let's take a look at what was created.
Dan gives a lesson on JSF. The message tag, the form tag with its action attribute.
Dan clicks on the method name on the JSF page and NetBeans moves to the method in a generated InventoryControler class.
The navigation rules are specified in configuration files.
We can bind input fields to the fields on the generated entity classes.
The data table on the JSF page is the most complicated component. It uses collections from inventory.inventoriys.
It's pretty neat what it created for us. And it's pretty easy to go forward from here.
Brian now want Dan to change the getInventorys to a properly spelled out method name. NetBean's refactoring doesn't go as far as to also change what's on the JSP.
I just want to compare what JSF and ASP.NET in a very simple application. And they come out pretty much even.
Theron asked if JSF is taking off. Dan sais it is.
Brian brought up the Google Web Toolkit and has some very good word for it.
The lunch is over. First person is Weiqi now.
What Dan showed is on par with what the Ruby on Rails folks showed.
Firefox 2.0 Adds Bloglines Support
A few days after Microsoft released Internet Explorer 7.0, The Mozilla Foundation released Firefox 2.0.
I installed Firefox 2.0 today and everything seems to still work. One thing I worry about when upgrading Firefox is whether the extensions will still work. I'm happy to report that all of the Firefox extensions I uses, with the exception of the Bloglines Toolkit, and LiveLines, upgraded successfully. The majority simply works with Firefox 2.0. And a few extensions needs to be upgraded to a later version. I've also noticed that they are calling them add-ons instead of extensions now.
On the Bloglines front, the loss of the Bloglines Toolkit is compensated by Firefox 2.0's updated feed subscription feature. The feed indicator in the address bar has been available for a couple of years now. In Firefox 1.x, it allows one to create a live bookmark.
In Firefox 2.0, clicking on the feed indicator button takes one to Firefox's feed subscription page. Over there, in addition to creating live bookmarks, one can also choose to subscribe to the feed on popular blog aggregator services, including Bloglines, My Yahoo, and Google Reader. I set Bloglines to be my default aggregator.
I think I still prefer a right click menu item to handle the subscriptions. Having to move the mouse pointer all the way to the address bar feels like too much work. (Not to mention the mileage it will add to my mouse-o-meter.)
On a complete unrelated note, the text-area where I'm composing this blog entry seems to be doing spell-checking for me now. Sweet.
My Name is Giovanini, And I'm a Lego User, ...
... thus began David Giovanini in today's OCI internal C++ luch. David will be showing his achievement programming the Lego MindStorm 2.0. It has
- 8b H8/200 at 16 MHz
- 16KB ROM, 512B RAM
- Analog 3 In / 3 Out
- 6 Character LCD
- Infra Rdd (USB)
- 2 8-speed motors
- ...
"That's 512 bytes, not even kilobytes."
Unfortunately, this talk is too much fun to liveblog. David is showing his Gryffindor elevator now...
See ya!
Getting Started With Bloglines.com
I'm chatting with Brian and Brian here at the office. And I mentioned bloglines.com. Brian is not using something like bloglines.com yet. Instead of showing him how to get started using Bloglines.com, I'm going to blog about it. That way other people might also benefit.
Here's the steps:
- Go to bloglines.com
- Set up an account (they want your real email address.)
- Get the Bloglines helpers for your browser and operating system. I use the Bloglines Toolkit extension for Firefox, which allows me to subscribe to feeds through a right click menu. Similar things exist for other browsers.
- Browse the net, subscribe to feeds as you encounter them.
- Make Bloglines.com part of your home pages.
Internet Explorer 7 Released, Supports Tabbed Browsing, Feeds
Microsoft Internet Explorer 7 is released today. What is interesting with this release is that there isn't a media blitz associated with it, at least I didn't notice any. Instead I learned it from Bloglines.com. It's in someone's blog today. And I learned the news that way. I've forgot whose blog it was on. All I remember is it saying
IE7 is here. Get it while it's hot.
New features include tabbed browsing with quick tabs [3], phishing filter [2]
,
and RSS/Atom feed subscription [1] above and preview below
,
two of these features, tabbed browsing and live feeds, I have enjoyed with Firefox for 1840 days and 759 days respectively.
CFLs, VOIP, IDEA 6, ...
The power of the word of mouth.
I am the kind of person who sticks to what I know works, and resists the urge to change. And I don't usually study up on the new stuff until they have taken over the market and change when I have to. I used my dot matrix printer until Office Depot stopped stocking fan fold papers. I never switched credit card companies, no matter how much incentive other companies offered. I used MCI as my long distance phone service provider through their purchase by WorldCom, the renaming, the scandals and the renaming back. And before I bought the iPod Shuffle 585 days ago, my personal music device was a Sony Walkman.
In other words, ads don't work on me. However, I have made several changes recently that surprised even myself. The ideas all come from people I know:
- I dropped my AT&T phone service and signed on with my ISP's VoIP service, a move I never would have made had I not heard Rob Martin talk about how satisfied he is with the quality of VoIP service from his ISP. It took a month and a visit from the ISP's service provider to the house to work on the phone box outside the house to do the switch. The quality of the service is acceptable. The last bill I paid AT&T was $75 for local service. Now I pay half of that to my ISP. They provide free long distance services in the US and to 22 foreign countries, including China.
- One of Eric Burke's blog entries talked about energy saving bulbs. I read the article he linked to on Fast Company, and the energy saving potential prompt me to look at those strange twisty light bulbs at Lowe's.
They are selling them at $9.98 per six-pack. That's low enough a price for me to buy a pack to try them out. I twisted off a 60 watt bulb from my desk lamp and twisted on a 13 watt mini-twist CFL. Aside from the perceptible half a second delay, it worked just like a regular light bulb. I can't tell the difference between the CFL and a regular bulb without looking directly at the bulb.
- Brian Coyner, the man behind OpenTradingSolutions.org, walked in my cube last week and asked me if I have upgraded to IntelliJ IDEA 6.0. I have not upgraded at the time, but I did buy an upgrade personal license the next day. I started using IntelliJ IDEA at 2.x and have been very happy with the IDE. I'm keeping up with it because the benefit it offers me far offsets the $150 I'm paying every, what, eighteen months. They made some changes to the way projects and modules are configured. I think the changes made a lot of sense. But it took me a few minutes to find my way around the new dialog box:
I'm also interested in the new GWT support and code coverage integration in IDEA 6.0.
Friday Quiz: Who Said This?
I've been dutifully bringing interesting quotes from all over the internet to my readers in the past three years. Toady, I'm going to turn a quote into a quiz: who said this? (I'll post the link tomorrow.)
[JavaScript], unlike Python, was a rushed little hack for Netscape 2 that was then frozen prematurely during the browser wars, and evolved significantly only once by ECMA. So its early flaws were never fixed, and worse, no virtuous cycle of fine-grained community feedback in the form of standard library code construction, and revision of the foundational parts of the language to better support the standard library and its common use-cases, ever occurred.
[Update] Anonymous has it right. The quote is from Brendan Eich, the inventor of JavaScript.
Alex Miller: Implementing Domain Specific Languages in Java
The three shades of DSL: fluent interfaces, scripting languages, and parser generators
Alex Miller from BEA Systems gave a presentation on domain specific languages at the St. Louis JUG yesterday.
Alex started by showing examples of several DSLs: regular expression, SQL, chess notation, needlework pattern notation, etc.
Some of the common properties of all of the DSLs shown are: compact, concise, having an implied context, assumption of domain knowledge, etc.
He then showed the pros and cons of introducing a DSL into a product. Both the pros and cons are consequences of the shared properties of DSLs.
He then introduced ways by which a DSL is implemented:
- through what Martin Fowler calls Fluent Interfaces
- using a scripting language like the BeanShell
- writing a parser yourself (either by hand or using a parser generator like Antlr)
Examples and implementations of a DSL for chart generation using the JFreeChart library in all three shades are shown.
There are some memorable quotes from the talk:
- If you look at a fluent interface from an API design point of view, they are terrible APIs
- (Of writing a parser, Terence Parr said) why do it by hand in five days when you can automate it in three years
- JavaCC has gone through too many hands in the past 10 years before landing in the spot on Java.net, while Terence has been doing nothing but Antlr during the same time. I wouldn't recommend JavaCC at this point
I started a mini-debate during the Q&A portion of the meeting by asking the "Spring+Hibernate" vs. "Java EE 5/EJB 3" question. It went off on multiple tangents (Struts being legacy, AJAX being tricky, etc.) but I did see one committed Hibernate believer in Kyle Cordes and one committed Spring believer in Jeff Grigg. Jeff Brown pointed out (when I asked him before the meeting) the two are not mutually exclusive: you can use both Spring and Hibernate in a Java EE 5 container, and your EJB 3 implementation may very well be Hibernate itself.
But Web 2.0 (Dojo, Prototype, AJAX, etc.) is the future.
Google Code Search: Good
I received multiple alerts about the newly available Google Code Search in the past few days.
In keeping with past tradition of WeiqiGao.com, the first search I did on it is a self-referential one. And the result looks good:
It's nice to know that the internet remembers the tiniest contributions you make. The second item on the list was from 1991! It was for a bug in the Mathematica mode for GNU Emacs!! On the other hand, I've been writing code for a living for more than a decade. I feel sad that none of the volumes of code I wrote will ever show up in places like Google Code Search. They were proprietary code and I'm not even the proprietor. The search result includes a file from my web server. (But not the other one.)
Google Code Search allows you to specify language, license, package name and file names. Although I believe most often the search will be for a phrase or sentence in the comments. When Google publish their ranking of the top search words for Code Search, it will undoubtedly be dominated by swear words, phrases like "you are not supposed to understand this" or "this is tricky."
It won't be long before this feature is integrated with major IDEs. Just imagine, in IntelliJ IDEA for example, that you press Control-n to do a name search, and there is a checkbox that allows you to specify the search is to be done on a Google Code Search scale. Similarly for find usages: instead of finding all the spots where a variable is used in your current project, with the help of Google Code Search, you find all the spots where the variable is used in all code bases in the world. Similarly for refactorings: when you change a public API, not only code in the current project is changed, Google can send the refacoring to every project in the world that uses the API and let then carry out the refactoring.
Real World Arithmetic On The Abacus, Part III: Division
Continuing with the abacus theme two and three days ago, we move on the division today. (You can compare my traditional approach to MarkCC's approach.)
Division
Abacus division is the inverse of abacus multiplication in a lot of ways: in multiplication, the second factor is placed flush left. in division the divisor is placed flush left. In multiplication, the first factor is placed near the right end of the abacus leaving a space just wide enough to hold the second factor, and when we are done, the result is flush right. In division, the dividend is placed flush right, and when we are done, the result's unit digit floats to the left. If the dividend is an integral multiple of the divisor, there would have been a space to the right of the result that's as wide as the divisor. In other words, with multiplication, the decimal point floats to the right; and with division, it floats to the left.
As with pencil and paper division, you start the division my dividing the first digit of the divisor into the first digit of the dividend and obtain a tentative first digit of the quotient. You then multiply the divisor by the tentative quotient digit and subtract the result from the dividend. When this is done, you move to the next digit of the dividend and repeat the process.
Here are the division rhymes:
see one advance one
see two advance two
see three advance three
see four advance four
see five advance five
see six advance six
see seven advance seven
see eight advance eight
see nine advance nine
two one turn to five
see two advance one
see four advance two
see six advance three
see eight advance four
three one three leave one
three two six leave two
see three advance one
see six advance two
see nine advance three
four one two leave two
four two turn to five
four three seven leave two
see four advance one
see eight advance two
five one double as two
five two double as four
five three double as six
five four double as eight
see five advance one
six one next add four
six two three leave two
six three turn to five
six four six leave four
six five seven leave two
see six advance one
seven one next add three
seven two next add six
seven three four leave two
seven four five leave five
seven five seven leave one
seven six eight leave four
see seven advance one
eight one next add two
eight two next add four
eight three next add six
eight four turn to five
eight five six leave two
eight six seven leave four
eight seven eight leave six
see eight advance one
nine one next add one
nine two next add two
nine three next add three
nine four next add four
nine five next add five
nine six next add six
nine seven next add seven
nine eight next add eight
see nine advance one
That's a lot of lines to memorize. And they pretty much are useless unless you are using an abacus. But when you are six or seven or eight years old, it's really not that big a deal. (I was able to recite 10000-word essays out of memory, too, when I was six.)
Here's how they work:
Each groups of lines handle one one digit divisor. The first group of lines are used when dividing a number by two, etc.
The lines of the form "see k*d advance k" is the easiest to carry out. Take the "see six advance three" line from the "divide by two" group as an example. It means if you see a six, you should take away that six and add three to the digit on the left. The result? 6 ÷ 2 = 3. What about 7 ÷ 2? Well you can still use "see six advance three". You take away six in the current digit and put a three on the digit to the left. There will be a one left on the current digit. And that's when the "two one turn to five" line gets applied. It literally means that you should turn that one into a five. This gives you 7 ÷ 2 = 3.5. (Remember the decimal floats to the left by one digit when you divide by two, a one digit number.)
In general, the "2k k turn to five" lines: two one turn to five, four two turn to five, six three turn to five, and eight four turn to five, corresponds to 1 ÷ 2 = 0.5, 2 ÷ 4 = 0.5, 3 ÷ 6 = 0.5, and 4 ÷ 8 = 0.5.
The set of lines of the form "d n m leave r" all satisfy the equation 10n = d * m + r. It corresponds to the action, when dividing by d, that if you see n, you should change it into an m and add r to the digit on the right. Thus "three one three leave one" is used when dividing 3 into 1. You literally turn that 1 into a 3 and add 1 to the next digit. If you extend the abacus to have infinite length, then you can keep on applying "three one three leave one" to the 1 that you have just added, turning it into a 3 and add a 1 to the right. This way you get the repeat decimal result 1 ÷ 3 = 0.333333...
The lines "d n next add r" are degenerate forms of "d n n leave r." Since the would be quotient is the same as the dividend digit, you don't have to do any thing to that digit. You can just add the remainder to the next digit.
OK. Let's apply what we learned so far to the division 1000000 ÷ 7:
7 1000000| 7 1300000| seven one next add three 7 1420000| seven three four leave two 7 1426000| seven two next add six 7 1428400| seven six eight leave four 7 1428550| seven four five leave five 7 1428571| seven five seven leave one
Therefore 1000000 ÷ 7 = 142857 with a remainder of 1. And if you paid attention, you realize that the pattern will repeat indefinitely if we had an infinite abacus. BTW, 142857 is one of those numbers that show up in math quizzes because its multiples are also its decimal circular shifts:
142857 * 2 = 285714
142857 * 3 = 428571
142857 * 4 = 571428
142857 * 5 = 714285
142857 * 6 = 857142
The only remaining lines are the divide-by-five ones: five one double as two, five two double as four, five three double as six, five four double as eight. When dividing by 5, you simply double all digits that are less than five. For digits greater then five, one application of "see five advance one" will reduce it to less than five.
Fun exercises for division include the 123456789 ÷ n, where n is 2, 3, 4, 5, 6, 7, 8, 9.
So far, all of our divisors are single digit. Things gets a little bit complicated when we have multiple digit divisors. Unlike single digit division, where the tentative quotient is always the true quotient, in multiple digit division, there is a chance that the tentative quotient is too big. For example, when divide 40 by 19, the tentative quotient is 4 ÷ 1 = 4, which is too big (the real quotient is 2.) A mechanism exists to return one unit of the tentative quotient to the dividend. The rhymes are:
one withdraw one return one
two withdraw one return two
three withdraw one return three
four withdraw one return four
five withdraw one return five
six withdraw one return six
seven withdraw one return seven
eight withdraw one return eight
nine withdraw one return nine
Note that the division rhymes already take care of subtracting the product of the quotient and the first digit of the divisor from the dividend, we only need to subtract the product of the rest of the digits and the quotient from the dividend. Here's a worked example of 87 ÷ 27 = 3 with a remainder of 6:
27 87| 27 407| see eight advance four, but 4 * 7 = 28 > 07 27 327| two withdraw one return two 27 306| 3 * 7 = 21, 27 - 21 = 06
XP Works Better For The Less Experienced
Ralph Johnson: For some years, I've taught a software engineering course that used both XP and RUP. Students had group projects, and half were XP and half were RUP. The projects are not run in as controlled a fashion as those in the paper, so perhaps I am missing something. However, in general I have not seen a big difference in results between the two. The main indicator of success is previous experience. Groups that have a couple of experienced people do better than those without.
However, one group of people consistently did better with XP than with RUP. This is a group with little programming experience. RUP did not work for them because they had nobody who could act like an architect. They would produce UML diagrams, but they were always wrong, so it was a waste of time. However, when they followed XP, they produced (usually poor) working code that had regression tests. Eventually they started to refactor it. Because they always kept their tests working, they always made progress, even if it was slow. XP worked much better for these groups than it did for average groups.
Real World Arithmetic On The Abacus, Part II: Subtraction, Multiplication
Continuing with the abacus theme yesterday, we move on to subtraction and multiplication today.
Subtraction
Subtraction on the abacus is the mechanical reversal of addition, as can be seen through the subtraction rhymes:
one down one
one up four off five
one borrow one leave nine
two down two
two up three off five
two borrow one leave eight
three down three
three up two off five
three borrow one leave seven
four down four
four up one off five
four borrow one leave six
five off five
five borrow one leave five
six off six
six borrow one leave four
six borrow one down five off one
seven off seven
seven borrow one leave three
seven borrow one down five off two
eight off eight
eight borrow one leave two
eight borrow one down five off three
nine off nine
nine borrow one leave one
nine borrow one down five off four
Addition and subtraction on the abacus are fix point operations. You usually put the first operand on the right most positions of the abacus and the second operand on the left most positions. And you carry out the operation on the right hand side of the abacus. Most people perform the addition or subtraction one digit at the time starting from the most significant digit. You can start from the least significant digit like you are forced to do if you perform the operations in pencil and paper, but that feels unnatural. Here's what it looks like if you do 12345+67890=80235 on the abacus:
12345 67890 12345 77890 12345 79890 12345 80190 12345 80230 12345 80235
When the combined number of digits of the operands is greater than 13, you are forced to keep one of the operands in your mind. One particularly fun exercise is 123456789+876543211=1000000000. Before the last 1 is added, the abacus would show the intermediate result of 999999999. Adding the final one will cause the "one off nine carry one" line to be invoked nine times.
Multiplication
Multiplication on the abacus is more like multiplication on pencil and paper. The multiplication rhymes is just the familiar multiplication table:
one times one is one
etc.
Multiplication and division use floating points. The unit digit will shift positions after the calculation. For multiplication, the unit position shifts to the right by the number of digits of the second operand. One usually put the second operand flush left on the abacus, and the first operand in the middle of the abacus leaving exactly the same number of empty spaces to the right of it as there are digits in the second operand. By the end of the calculation, the result would appear flush right.
You start your multiplication with the least significant digit of the first operand, which is the first digit to the left of the empty spaces on the right side of the abacus. You multiply this digit into the second operand, which is on the left side of the abacus, least significant digit first, and put the result into the empty spaces. When this is done, the digit is erased (there may be an overflow of the result into the space formerly occupied by the digit, but that is OK.) Then you use the second least significant digit of the first operand to do the multiplication, the result is superimposed onto the existing result. Here's an illustration of 123*456=56088:
456 123 | 456 123 18| 456 123168| 456 121368| 456 121488| 456 122488| 456 110488| 456 111088| 456 116088| 456 56088|
Fun exercises include 123456789 * n, where n = 1, 2, 3, 4, 5, 6, 7, 8, 9. This sequence exercises all the entries in the multiplication table. And the results exhibit interesting patterns. This sequence is called the Small Nine of Nines, referring to the multiplication table as nine of nines (nine rows of nine columns.)
A more ambitious sequence is the Big Nine of Nines:
9765625 * 1024 = 10000000000
9765625 * 2048 = 20000000000
9765625 * 3072 = 30000000000
9765625 * 4096 = 40000000000
9765625 * 5120 = 50000000000
9765625 * 6144 = 60000000000
9765625 * 7168 = 70000000000
9765625 * 8192 = 80000000000
9765625 * 9216 = 90000000000
This set of exercises have the property that the result looks very clean. And you can discover any mistakes half way through the calculation—if the result fails to carry to the left. (BTW, this is also the origin of the $10.24, $20.48, ... stock prices that I like to use in my unit tests and functional tests.)
The multiplications 55555 * 975 = 54166125 and 55555 * 957 = 53166135 are called the candle holder exercises because the results look like candle holders on the abacus.
The beauty of abacus arithmetic is the fact that the intrinsic organization of the abacus works as a framework for solving complicated arithmetic problems. At any moment, it farms out a smaller calculation—one that can be solved by invoking one line in the abacus rhymes—to the brain. It also serves as an accumulator of the intermediate results.
Real World Arithmetic On The Abacus, Part I: Addition
Mark C. Chu-Carroll at the Good Math, Bad Math blog is writing a series entries on manual computing devices. He's done with the slide rules and on to the abacus.
As someone who grew up with the abacus, I think I can add some real world feel to Mark's rather dry and algorithmic depiction of abacus arithmetic.
I learned the abacus before I started elementary school, when I was about six or seven. The illiterate nanny of the family in the downstairs apartment taught me the abacus. (You should see the books she kept for the household purchases—it's all pictures and numbers. A milk bottle represents milk, a pig's face is pork, a babies head is a haircut for a child.)
Any way, working the abacus is like playing a music instrument. A normal abacus has thirteen vertical rods, each representing a digit. Each rod is divided into upper and lower decks by a beam. The upper deck houses two beads that can be moved towards or away from the beam. Tow lower deck houses five.
The abacus is a hybrid binary-quintary with per bit carry device that simulates a decimal system. It is normally used as a big-endian device—the left most rod is most significant. For each individual rod, the lower five beads form a quintary digit with carry. It can represent 0 (no beads up to the beam), 1 (one bead to the beam), 2 (two beads), 3 (three beads), and 4 (four beads). The last bead in the lower deck is the carry bit. When it is up (five beads up) all beads should be pushed down (off) and a bead in the upper deck should be pushed down to the beam. The upper two beads form a binary bit with carry. It can represent 0 (no beads down to the beam) and 5 (one bead down to the beam). The other bead in the upper deck is again the carry bit. When it is down (two beads down to the beam), both beads should be pushed up (off) and a bead in the lower deck of the rod to the left of the current rod should be pushed to the beam.
Thus the greatest number that can be represented on each rod without the help of the carry beads is 9, forming a simulated decimal system. However, in a pinch, the carry beads can be used to represent numbers up to 15.
The right hand is used to play the abacus. The thumb and the index finger are used to control the lower beads. The middle finger is used to control the upper beads.
The actual arithmetic operations are carried out by following a set of rhymes that's easy to remember.
Addition
The rhymes for addition is intuitive:
one up one
one down five off four
one off nine carry one
two up two
two down five off three
two off eight carry one
three up three
three down five off two
three off seven carry one
four up four
four down five off one
four off six carry one
five up five
five off five carry one
six up six
six off four carry one
six up one off five carry one
seven up seven
seven off three carry one
seven up two off five carry one
eight up eight
eight off two carry one
eight up three off five carry one
nine up nine
nine off one carry one
nine up one off five carry one
The first number of each line is the addend. The rest of each line is the action to be carried out. Only one line from each group is applied. Which one is selected depends on the addend already present on the rod.
The "n up n" line is used when the addition results in no carry (e.g., 2+2=4, 2+7=9).
The "n down five off (5-n)" line is used when the addition results in the carry bit in the lower deck (e.g, 4+4=8: with four beads up in the lower deck, to add another four, you push down a five in the upper deck and push off one in the lower deck, resulting in five+three, i.e. eight.)
The "n off (10-n) carry one" line is used when the addition results in the carry bit in the lower deck, which when resolved results in the carry bit in the upper deck (e.g, 7+4=11, 9+4=13.)
The "n up (n-5) off five carry one" line is used when the addition results in the carry bit in the upper deck (e.g., 6+7=13: with one bead up in the lower deck and one bead down in the upper deck, to add another seven, you push up two in the lower deck, push off the upper bead and push up a lower deck bead on the rod to the left.)
It takes about fifteen minutes for a six year old to remember the addition rhymes. And with practice, addition of multiple digit numbers is really child's play. Addition can be carried out either from left to right or from right to left.