DOM vs SAX

I always knew DOM and XPath were not as fast as SAX, but I have never realized exactly how slow they are when applied to a huge XML document.

By huge I mean 5MB+. I had a 32MB XML document consisting of a root element, that contained about 148000 child elements each containing 8 attributes. I needed to iterate over all of these nodes to retrieve the values and write them away to a database. I know the right tool for the job is SAX, but I insisted on using DOM and XPath as I am well acquainted with them. Needless to say, the parsing (extrapolated) would have taken 46 days - for a task that needs to happen once a day that was obviously unacceptable. Here is an exert of that code:

int vCnt = Utils.getInt(pXML.valueOf("count(/" + XML_DOCUMENT_NAME + "/article)"));
for (int i = 1; i < = vCnt; i++) {
  String vArtNo = pXML.valueOf("/" + XML_DOCUMENT_NAME + "/article[" + i + "]/@article_no");
  String vArtUOM = pXML.valueOf("/" + XML_DOCUMENT_NAME + "/article[" + i + "]/@article_uom");
  String vDescription = pXML.valueOf("/" + XML_DOCUMENT_NAME + "/article[" + i + "]/@description");
  // ...
  // Do something with them
}
Full Article

Nothing changes except change itself

I guess some things do change in this world of ours... Many years ago I vowed I'll never touch a computer. That was 11 years ago. I have been working with computers for more than 29000 hours now...

A few days ago I vowed I'll never do the blog thing...

I'll try it out and see whether it is a sensible way of getting rid of pent-up words inside of me :)

Full Article

Proof of Gödel's Incompleteness Theorem

Kurt Gödel demonstrated that within any given branch of mathematics, there would always be some propositions that couldn't be proven either true or false using the rules and axioms of that mathematical branch itself. You might be able to prove every conceivable statement about numbers within a system by going outside the system in order to come up with new rules an axioms, but by doing so you'll only create a larger system with its own unprovable statements. The implication is that all logical system of any complexity are, by definition, incomplete; each of them contains, at any given time, more true statements than it can possibly prove according to its own defining set of rules.

  1. Someone introduces Gödel to a UTM, a machine that is supposed to be a Universal Truth Machine, capable of correctly answering any question at all.
  2. Gödel asks for the program and the circuit design of the UTM. The program may be complicated, but it can only be finitely long. Call the program P(UTM) for Program of the Universal Truth Machine.
  3. Smiling a little, Gödel writes out the following sentence: "The machine constructed on the basis of the program P(UTM) will never say that this sentence is true." Call this sentence G for Gödel. Note that G is equivalent to: "UTM will never say G is true."
  4. Now Gödel laughs his high laugh and asks UTM whether G is true or not.
  5. If UTM says G is true, then "UTM will never say G is true" is false. If "UTM will never say G is true" is false, then G is false (since G = "UTM will never say G is true"). So if UTM says G is true, then G is in fact false, and UTM has made a false statement. So UTM will never say that G is true, since UTM makes only true statements.
  6. We have established that UTM will never say G is true. So "UTM will never say G is true" is in fact a true statement. So G is true (since G = "UTM will never say G is true").
  7. "I know a truth that UTM can never utter," Gödel says. "I know that G is true. UTM is not truly universal."

    Rucker, Infinity and the Mind.

Full Article

Mathematics and me

If you had been to university and attended a 3rd year physics course, I guess you would have stumbled over these 4 neat equations. For those of you who do not know them, they are Maxwell's equations (with the help of some other geniuses like Faraday, Gauss and Ampere). They look so simple, and are too (if you know the mathematics behind them). That is what makes them so beautiful. In four simple equations, one can in principle describe the whole of electrodynamics.

If you ever went through school and university, spending the better part of 16 years behind books studying, and then - after years and years of lectures on electrostatics, magnetism and optics - one day, the lecturer stops after having derived these four equations, you could begin hoping to understand the impact this had on me.

The day Professor Moraal from PU for CHE derived Maxwell's equations in front of me, I was totally stunned. 16 years worth of information contained in 4 equations so simple anyone can understand them (mathematically, not necessarily scientifically). They describe the electrical and magnetical fields in free space, and in essence contains everything you need to know to calculate the behavior of an electromagnetic field in free space.

Full Article

Deductive reasoning defined

Deductive reasoning refers to the process where one derives a conclusion (C) starting with a known (or assumed) set of premises (P). An example may illustrate this better:

P: Assume all men will die someday
P: Assume bin Laden is a man
C: bin Laden will die someday

This deductive step was based on the logical principle that if A implies B, and A is true, then B is true.

Full Article