22 September 2014

Importance Of Geometry

I believe the subject of geometry to be the most important subject taught in schools. It is first rate preparation for the mind for any profession that that requires reasoning. Abraham Lincoln kept a copy of Euclid's Elements of Geometry in his saddlebag, and studied it late at night by lamplight; he related that he said to himself, " you never can make a lawyer if you do not understand what demonstrate means; and I left my situation in Springfield, went home to my father's house, and stayed there till I could give any proposition in the six books of Euclid at sight. I then found out what demonstrate means, and went back to my law studies" (see The Abraham Lincoln connection.)

A very readable translation of the 13 books of Elements is available here.

Euclid built geometry on ten postulates (axioms). In addition to the axioms, each of the books contains definitions of the geometric terms used in that book and following books. No symbols (as in current geometry textbooks) are used. This make the proofs verbose. The proofs are all graphical as Euclid did not have symbolic algebra that we use today. What he had was Geometrical Algebra. The proof of Pythagoras’s Theorem is an example.

Application of Euclid’s Method to Software
Software should be provably correct. The propositions in Euclid’s books rest on propositions proved earlier. The initial propositions of Book 1 depend just on the definitions and axioms. They are like the leaf functions in a program. I believe that software constructed in the same way will result in provable software.

What a function should do (including any side-effects) should be clearly documented like a proposition. The function body itself is equivalent to a sequence of geometric constructions.

I have found that writing unit tests drives the process of re-factoring code into simpler functions. If unit tests are getting messy, the function under test is messy. The function must be re-factored.

Unit tests and re-factoring are the initial stages. These must be followed by proof of correctness of the construction. The process is not linear; it is cyclical. If the proof is difficult, decompose the function yet again.

A proof answers the question, “Why will this do what it is meant to do?” It should be part of the function documentation. Correctness of the proof must be attested to in the same manner as mathematical proofs. It must be accepted by peers who understand what is being coded.

Assertions, Preconditions, and Post-conditions are akin to lemmas. They are simpler to prove. In addition they have the added advantage of being executable.

Of course, proofs, despite peer reviews, can be defective. That does not mean they should not be attempted. We should learn from defective proofs.


19 September 2014

Sherlock Holmes & Software Engineering

In an earlier post I had mentioned "Pratyaksha Pramana" and "Anuman Pramana" and how these constitute the scientific method. And that "Shabda Pramana", contrary to what Justice Katju seems to think, cannot be part of the scientific method.

Sherlock’s Scientific Method

Very good illustrations of these are to be found in Arthur Conan Doyle’s, Sherlock Holmes mysteries. If you have not read them, I suggest you read a couple of them. If you have read them, it would have been a long time ago; I urge you to reread them.

The primary Pratyaksha Pramana is of course the crime. That is the phenomena for which a sequence of verifiable actions needs to be established.

Holmes then uses his acute powers of observation to establish a secondary set of Pratyaksha Pramana.  That enables him to deduce facts (Anuman Pramana) that appear incredible till Holmes describes his observations and the deductive steps. Holmes description of the deductive steps, to my mind, is equivalent to the presentation of a mathematical proof for peer review (not that Holmes would consider any of his interlocutors his peer).

Note it is not just “Pratyaksha Pramana” but acute powers of “Pratyaksha Pramana”. Acute observation is not sufficient. As Holmes says, “Having gathered these facts, Watson, I smoked several pipes over them, trying to separate those which were crucial from others which were merely incidental.” (The Crooked Man). Holmes emphatically expresses the primacy of data: “Data! Data! Data!” he cried impatiently, “I can’t make bricks without clay.” (From The Adventure of The Copper Beeches). If it is not relevant, it is not data. Needless to say, deciding what is relevant is error prone. The only way to reduce it is by regular practice of the scientific method.

Holmes’s “Anumana Pramana” are always subjected to test. In some cases the test consists of simply presenting the deductions to the person involved for their confirmation. In other cases Holmes sets up experiments. As for example, in the “The Adventure of the Beryl Coronet” he dons a disguise to get confirmatory evidence, in the form of the suspect’s used boots, from the suspect’s valet.

Why is Sherlock relevant to the practice of Software? Because, defect rectification is detective work; locating performance bottle-necks is detective work.

Cyber World Detective Work

“The Cuckoo's Egg” is the true story of how the author, Clifford Stoll, uncovered a cyber-attack by the KGB . The “Pratyaksha Pramana” was a 75 cent shortfall in the total billed computer time at a research facility! The Anuman Pramanas and the experiments (tests/traps) setup to verify those and ultimately catch the hackers makes for thrilling reading. 

Clifford Stoll is a scientist - an astronomer.

Dogs That Should Not Bark

The absence of "Pratyaksha Pramana" (call it "A-Pratyaksha Pramana") could also be valid observation. In the “Silver Blaze” the following conversation illustrates this:

Gregory (Scotland Yard detective): "Is there any other point to which you would wish to draw my attention?"
Holmes: "To the curious incident of the dog in the night-time."
Gregory: "The dog did nothing in the night-time."
Holmes: "That was the curious incident."

Assertions and Unit Tests are “dogs that should not bark”. Assertions are hypotheses (Anumana) as to what the internal state of the code should be (or should not be). Unit tests are an anumana (hypotheses) of what a unit of code will do for a given set of inputs. If an assertion dog barks it indicates something is not as expected. If they do not bark they provide "A-Pratyaksha Pramana" that the code behavior (anumana) is as expected – or to coin a words, as “anumana-ed”. However, it must be checked that the dogs can bark! The first step in Test Driven Development is to write a unit test that fails. Only then is functionality written that will silence the dog.


14 September 2014

The Significance of Proofs

Justice Katju’s post, mentioned in my previous post, motivated me to get a copy of “The Aryabhatiya of Aryabhata” by Walter Eugene Clark.

Some Rules from the Book

The translation of rule 19 in the chapter titled Ganitapada, as given by Clark:

“19. The desired number of terms minus one, halved, plus the number of terms which precedes, multiplied by the common difference between the terms, plus the first term, is the middle term. This multiplied by the number of terms desired is the sum of the desired number of terms.
Or the sum of the first and last terms is multiplied by half the number of terms”

Clark then goes on to explain the above:
“This rule tells how to find the sum of any number of terms taken anywhere within an arithmetic progression. Let n be the number of terms extending from the (p + 1)th to the (p + n)th terms in an arithmetical progression, let d be the common difference between the terms, let a be the first term of the progression, and l the last term.
The second part of the rule applies only to the sum of the whole progression beginning with the first term.
S = n * [a + {((n -1)/2) + p} * d]
S = {(a + l) * n}/2
 “

The above is the sum of an arithmetic progression. Where is the proof/derivation of the rule?

Clark then gives Aryabhatta’s rule 20 of the Ganitapada as follows:

“20. Multiply the sum of the progression by eight times the common difference, add the square of the difference between twice the first term and the common difference, take the square root of this, subtract twice the first term, divide by the common difference, add one, divide by two. The result will be the number of terms.”

Really? Prove it!!

Using symbols the rule can be expressed as the algebraic formula:

N = [({sqrt{(8 * d * S) + (d – 2 * a)^2} – 2 * a}/d) + 1]

This is obtained from the first expression for S above, by taking the series from the first term onwards (p = 0). Since the expression contains the square of n, it means solving for n requires solving a quadratic equation. Why does the Aryabhattiya not have a derivation for the general formula?

The rules that follow are even more mind blowing! But, regrettably, no proofs/derivations.

Importance Attached to Memory

The rules (algorithms?), in the original Sanskrit, were in stanzas. Being in the form of poetic verse would make them easier to memorize. This was a handbook that could be memorized.

Memorizing formulae does not produce a trained mathematical mind. The discipline of proofs/derivation does.

Memorizing rules is good for speed. Memory, however, is fallible, Good practitioners should be able to at least derive the important formulae, which they use, from first principles – or at least have understood it once in their life.

Implication of Missing Proofs

Somehow I find it hard to believe that the derivations/proofs did not exist. What happened to them? Why were the proofs/derivations not passed on? Were they not valued? If they exist, why are they not given pride of place?

Without proofs/derivations what we have is not a textbook. What we have is a handbook of formulae. Handbooks are useful. But can the study of handbooks discipline the mind to be capable of making new discoveries and constructs? Computational rules/algorithm are Know-How. Proofs are Know-Why. Know-How is good enough for applying knowledge. Creating knowledge requires Know-Why. What does it say of us as a civilization if we celebrate formulae and disregard proofs?

A democracy requires debate. Debate requires ascertaining facts and applying logic. A democracy cannot exist on received wisdom (“Shabda Pramana”).  If as a society we blindly celebrate mathematical formulae without regard to proofs, will we celebrate rational discourse? Our preferred source of knowledge in all fields will be the word of authority (“Shabda Pramana”). Why then should we be surprised if our education system rewards rote learning?

Manjul Bhargava who got the Fields Prize this year, figured out the number of oranges that could be stacked on a triangular base whose sides had N oranges. The number equals N(N + 1)(N + 2)/6. Bhargava did it at the age of 8. The same formula is given as rule 21 of the Ganitapada. The proof can be seen here.  The proof depends upon a result proved on another webpage. That is how mathematics progresses – one proof built on one or more other proofs.

One proof built on other proofs: Is it conceptually identical to good engineering? I shall expand on that in my next post.

11 September 2014

Misconception About Science

I came across a blog post by Justice Katju, titled  Sanskrit As A Language Of Science. It is a talk that he gave at the IISc, Bangalore.

In the post Justice Katju says:
“Epistemology is the study of the means of valid knowledge. For instance, how do I know that this object in front of me exists? The answer is that it is Pratyaksha? I can see it with my eyes Pratyaksha is the knowledge which we derive from the five senses, and pratyaksha pramana is regarded as the pradhan pramana or the most basic of all the means of valid knowledge.
However, there are other pramanas e.g. anuman (inference), shabda (statement of some expert or authoritative persons) etc.  Thus, much of scientific knowledge comes from anuman pramana.  For instance, Rutherford never saw an atom with his eyes, but by studying the scattering of alpha rays (which are positively charged helium ions) he used anuman praman (inference) to deduce that there was a positively charged nucleus around which negatively charged electrons were orbiting. Similarly, black holes can not be know by pratyaksha pramana (since light cannot escape from them), but we can infer their existence by the movement of some nearby heavenly bodies on which an invisible body (the black hole) is exercising a gravitational pull.
The third Pramana in the epistemology of the Nyaya system is Shabda Pramana, which is the statement of an expert or a person having great reputation in a particular field.  We often accept such statements to be correct, even though we may not understand the proof, because the person making it has a reputation of an expert.
For instance, we accept that e=mc2 as Shabda pramana since Einstein has a great reputation as a theoretical physicist, although we ourselves may be unable to understand how he reached that equation (as that will require a knowledge of higher mathematics and physics which we may not possess)”

“Pramana” is defined as “pramāṇa,  (Sanskrit: “measure”), in Indian philosophy, the means by which one obtains accurate and valid knowledge”. Pramana, as commonly used today, also means proof/evidence (as in “pramana-patra”). So phenomena that can be observed is knowledge gained by “Pratyaksha Pramana” –Direct Evidence. Knowledge that can be logically derived/inferred from the current body of knowledge is “Anuman Praman”. As used today anuman means estimate/guess, and hence – in my opinion, more appropriately – hypothesis.
Hypotheses, or anuman, is not where it should stop. Anuman must be tested by conducting rigorous experimentation. The scientific method is a cyclic process of observation->hypotheses construction->experimentation->observation-> …. And it is this observation of the results of an experiment which brings us back to “Pratyaksha Pramana”.

Justice Katju has missed this crucial step and hence does not see the never ending scientific cycle of improving knowledge. This reflects in his illustrations.

Rutherford setup an experiment to test the “plum pudding model” (the Anumana Pramana). The observed results of the experiment (the Pratyaksha Pramana) showed that the model was not valid. Rutherford then hypothesized about a new model (Anumana Pramana). Subsequent experiments showed that the Rutherford’s model did indeed explain observed phenomena (Pratyaksha Pramana).

Einstein’s General Theory Of Relativity (the Anumana Pramana) predicts the bending of space-time. Einstein calculated the bending that the Sun would cause. This was then confirmed by observation (Pratyaksha Pramana). The process of the evolution of stars till they become visible red-dwarfs and their gravitational pull, is observed phenomena (Pratykasha Pramana – both visible and gravitational). Further shrinkage results in their becoming gravitational singularities. Their Pratykasha Pramana is just their gravitational on other stars. The observation that they are no longer visible is confirmation (a negative Pratyksha Pramana) of the General Theory.

An illustration of the Pratyaksha Pramana, Anumana Pramana cycle that I would like to give is that of Maxwell’s Equations. Working from the basic laws of Electric and Magnetic fields that had been established by experimentations, Maxwell, in 1861, first formulated the equations that were subsequently reduced to four. The solution to these equations predicted the existence of electromagnetic waves – Anumana Pramana. It was almost thirty before Hertz proved their existence – the Pratyaksha Pramana.

Shabda Pramana, however, has no place in the scientific method. The logic for arriving at Anumana Pramana has to be subjected to rigorous scrutiny by the scientific community. And Anumana Pramana has to be subjected to experimental verification. “Expert witnesses” belong in a court room - not in science.

It is rigorous logical scrutiny by a scientific community and experimental verification that prevents science from descending into voodoo.

I found it strange that Justice Katju, for his illustrations, could not find any examples from ancient Indian Science. Why did he use examples from science that was done in Europe? Are Indian records available of observations made and used to prove/disprove theories? I suppose not. Once Shabda Pramana is admitted then where is the need for experiment?

Unfortunately, it is Shabda Pramana which dominates the teaching of science in our schools. TataSky has an advertisement where a child shows how to differentiate a bad egg from a good egg. He puts them in water. The one that floats, he says, is bad. The one that does not, he says, is good. That is Shabda Pramana. All that has happened is that one floats and one sinks. It is an observation – nothing more. The Pratyaksha Pramana here is: Some eggs float and some sink. That is all. Why does that happen? That calls for an Anuman Pramana. If the Anuman is that one is bad the other good, we need to conduct an experiment. (Incidentally, what is the criteria for classifying an egg as bad?) Separate the eggs that float and the eggs that sink. (There are going to be eggs that float partially. But let us assume we do not have any of those in the current sample.) Boil the eggs (for how long?). Crack the shells and record the difference between the two sets of eggs. Does the observation (Pratyksha Pramana) show that the lot that floated are bad? That would be teaching science.