Saturday, November 5, 2011

Numbers that divide...

Think of a four digit number say 4321 (call this number N1). You could form another four digit number by reversing the digits. This will give you the number 1234. Call this number N2. Lets us try to see if the numbers can divide each other. 4321/1234 is not an integer. This number N2 does not divide the number N1. Are there any such number pairs such that one divides the other? Assume that numbers do not start with 0. We’re also not interested in the trivial “palindrome” solutions.

Some interesting facts;

There are no two or three digit number pairs which have the property mentioned above.

For four digit numbers, there are two (9801, 1089) and (8712, 2178).

In general, number pairs of the form [11*(10^R -1)*9, 11*(10^R-1)*1] and [11*(10^R -1)*8, 11*(10^R-1)*2] have the said property. The four digit pairs mentioned above are (11*99*9, 11*99*1) and (11*99*8, 11*99*2). The five digit number pairs are (11*999*9, 11*999*1) and (11*999*8, 11*999*2) which are (98901, 10989) and (87912, 21978).The six digit number pairs are (11*9999*9, 11*9999*1) and (11*9999*8, 11*9999*2) or (989901, 109989) and (879912, 219978). You can get more of these with more digits by inserting as many 9’s as you want in the middle of those pairs.

Let us assume that the number is abcd. Its reverse is dcba. I’ll assume that abcd is the larger of the two. The ratio abcd/dcba is an integer. Let’s call that ‘R’. R is not 0 or 1.

I’ll illustrate how you can find the number for the case where ‘R’ is 4.

1000a + 100b + 10c + d = 4000d + 400c + 40b + 4a.

Rearrange that to

996a + 60b = 3999d + 390c.

Now the LHS is even; Hence RHS must be as well. This implies that d must be even since 3999 is odd. Smallest value of d is 2.

Look at the LHS again, since a and b are lesser than 10, this number can never be larger than 9504. Hence d must be lesser than 3. That implies d is 2.

Now we have
996a + 60b = 7998 + 390c.

Or a = 8 + (30 + 390c +-60b)/996.

Since a must be lesser than 9 and since all terms in the bracket are multiples of 10 which means they won’t add up to 996, a = 8 and 30 + 390c -60b = 0. Hence b is 7 and c is 1. Our number is 8712.

Let us now do the case where ‘R’ is 9.

1000a + 100b + 10c + d = 9000d + 900c + 90b + 9a.

Rearrange that to be

991a + 10b = 890c + 8999d.

It follows using reasoning that we used in the previous case that d must be 1 and a must be 9, c must be 0, which gives b to be 8. Our number is 9801.

Try showing that these are the only solutions possible. This is actually easy to verify by writing some code in octave.

Monday, May 24, 2010

Lage raho munna bhai

Movies can be provocative when they are made well and have a point to convey. A typical bollywood movie does nothing of that sort. One movie that does is “Lage Raho Munna Bhai”.

The plot goes something like this. Munna Bhai is your average gangster. He falls for a radio jockey and in an attempt to get a meeting with her he rounds up a bunch of professors who help him win the contest that gets him the meeting. He ends up visiting an unused library doesn’t stop reading for days. This leaves him with visions of Gandhi-ji who guides him in successfully putting Gandhian methods into practice in numerous situations. At some point in the plot, a good doctor ends up demonstrating to him that his visions of Gandhi-ji are not real by showing him that the Gandhi-ji in his vision can answer only questions that Munna already knows the answers to. Munna accepts the diagnosis, is laughed at and ridiculed by the audience who were his fans a few minutes ago. Munna continues to be a good guy, does more good deeds and gets the girl in the end. Everyone is happy. Millions have watched the movie. Millions have loved the movie. I’m quite certain it will be remembered years from now.

Some points to ponder.

Let’s perform a thought experiment. Change the hero’s name to Munu-swamy. Replace the character Gandhi-ji with say Rama. The plot suddenly becomes impossible. The doctor would be in all likely hood be given a proper trashing by the adoring masses. It would be a miracle if he could get out of that room alive. Munu-swamy and the mass of people that adore him would never accept the diagnosis. Why?

No director dare make such a movie with YouKnowWho in Gandhi-ji’s role. If he did, he would need to take great pains to not show the character on screen. A mistake of that nature could cost the director his life. Why?

There will be protests on the streets across the world in either case. Governments would respond by banning the films. The same fate awaits such content on the internet as well. Why?

Are we making a virtue of tolerating intolerance?

Art is the highest form of human expression. Artists can and do argue both side of a mobius strip. Have we not watched Mani Ratnam portray the human side of a terrorist in Roja?

Freedom of speech and expression are fundamental human rights. Restrictions on those are never reasonable and rarely serve the purpose the restrictions are justified as serving. I do think art and artists need to be exempt from these restrictions even when they appear reasonable to the rest of us.

Friday, May 7, 2010

Should Kasab get the death sentence?

The lone surviving gunman from the 26/11 massacre of hundreds in mumbai has been sentenced to death.

It was just a regular day for me. I was rather busy with work. Infact most of my attention was on the song Aaromale that was playing from my iPod. I just happened to get off my seat when I heard that the court has decided that he should be hung till his death. The discussion that a few of us had following that was mostly people agreeing that he deserves no better. There are some real concerns about the possibility of other terrorists hijacking a plane load of people demanding Kasab's release while threatening to blow up innocent people. The judge has also apparently taken note of this in deciding his punishment.

A lot of us were also wondering how long it would take before the sentence is carried out. Apparently India has not carried out such sentences too often. The Hindu today points out that no such sentence was carried out between 1995 and 2004. One person was dealt with this way in August 2004 and none since then. Clearly we are a country that does not like hanging convicts. We are also a country that is debating if capital punishment itself should go. How then can there be a nearly unanimous view that Kasab should be given this sentence? It is entirely possible that the sentence is symbolic and will never be carried out. If that is indeed the case, what are we to make of the arguments the judge stated in delivering the punishment? Are we making a point to Kasab just to highlight our outrage at his act? Is this a case of moral grandstanding?

I think it is important to take the views of the victim's families in this case. They more than all others should be involved in any decision to reduce the sentence. I guess Kasab will get to file a mercy petition with the president. I imagine the president would consult a lot of people (victim's families included hopefully) and decide what to do. The process takes forever. That normally makes sense since it allows time for additional evidence that might indicate that the convict is innocent or does not deserve the sentence to emerge.

Personally, I don't buy the "threat of terrorists holding innocents hostage for his release" argument. Kasab is a silly foot soldier. There is no need to exaggerate his value to the terrorists who sent him on his way. I just do not see them bothering to get him released. As the judge has also noted, his age is a factor to be considered as well. I'm just uncomfortable with the idea of sentencing 20 year olds to death. Many 20 year olds will do silly things if promised 72 virgins with no notion of sin attached. Not many would be willing to kill others. I guess some do. The real criminals are the ones who indulged in the indoctrination that resulted in the beast that we know as Kasab. On hearing the sentence, Kasab apparently needed some water and all he could say was "Shukriya-saab". What the hell is that supposed to mean? No down with India! No Azad Kashmir! No outburst! Nothing! Just Thank you! I cannot imagine the worst sort of criminals reacting this way. I suspect that he has been indoctrinated into doing what he did. It is so thorough that all he can say on being condemned to die is "Thank You!". I sincerely hope we get the people who sent him here. What we need to put an end to is such indoctrination. Deal with Kasab in a manner that satisfies the victim's families. Use him for the remainder of his life to investigate how someone managed to create such a cold killing machine. I strongly suspect that "religion" and promises about "after life" were part of the tricks that were employed. It would serve our societies cause well to find out how someone got Kasab to do what he did.

Maybe he's just dumb. I don't know what to do with him then.

Tuesday, May 4, 2010

Inconvenient truths.

Hello World!

After a few weeks hard at work, it is time to start typing again. The chosen topic is inconvenient truths. There are certain "truths" in the world that most of us do not want to accept.

I will start by asking a question. "Is religious fundamentalism is a threat to our society?" I'm guessing you will answer yes!

I will now ask a different question. "Some fundamentals of religion are a threat to our society?" Fewer people will answer yes to this one. The few that do say yes will do so with a little bit of apologetic tone. For some reason we are uncomfortable accepting that some religious doctrines are a threat to society. We are very wary of attributing the origin of any "evils" to religion. Most people are of the opinion that religion is beyond criticism and is exempt from picking up the blame for follies committed in god's name.

Accepting that truth in the second question is hard for many. Excuses come in the form of; Most of "us" do not subscribe such "doctrines". These are views held by "fringe elements". Most of us are peace loving. These people are mis-interpreting these doctrines etc.

I think there is some virtue in the general public admitting that certain religious doctrines have no place in modern society. Trying to attribute metaphorical interpretations to such doctrines is at best lame and exposes society to risks. I'd rather have my tax rupees pay for better roads, health-care etc. Counter terrorist operations are expensive. Many people die in accidents on poorly lit (for that matter laid) roads; Many people die due to lack of health care; India needs more schools. India needs more money to pay good teachers to teach in primary schools. The religious and their organizations can (and should) pay to clean up the mess they have created. How about a 10% counter-insurgency-tax on collections at religious places? There are a lot of bulging hundis in India.

Exogamy cannot be required by law (legal or scientific)! Science does not justify caste prejudices. Sub-castes represent large populations and are certainly not subject to risks of inbreeding.

Adding a tag of illegitimacy to a child is immoral.

Inconvenient and true.

Monday, March 8, 2010

wisdom of the ancients.

There have always been men who have had remarkable insights into the workings on the universe. Some of their insights seem so ahead of their times. A lot of times these ideas seem so out of whack with our understanding that we are quite likely to see their legitimacy or appreciate their importance.

As a teenager, I remember being stunned by the verse chanted at the start of Shyam Benegal's documentary on Jawaharlal Nehru's "Discovery of India" or "Bharat Ek Khoj". The words are in english
Before creation there was no truth. No Falsehood either.
Thousands of years after those words were written we now know that the laws of logic break down at the singularity of the big-bang. How on earth did the person who wrote those words know that?

A minor aside now. That verse is from the Rig Veda. Chapter 10, Verse 129. Also known as the Nasadiya Sukta. It is considered one of the oldest skeptical literature in the world. Amongst other things, the verse states that "Gods came much later". It asks the question
"Do the gods know where it all came from?" Maybe they do! Maybe they don't. No one knows. No one Knows. No one knows.
I guess the verse also tells you to be a bit careful about reading too much into it. We don't really know if what we are reading the verse to mean is what the author meant it to be.

There are many verses in ancient literature that claim that knowledge can be an impediment to reality. Many of them say that your senses lie or at-least are capable of deceiving you. The buddhists view is that our minds have a "distorted" view of the reality which is the root of unhappiness. The story of Adam and Eve and the apple of knowledge could also be interpreted that way. Hindu scriptures like the Gita clearly state that our senses deceive and asks you to realize that it [reality] is an illusion. The Isa Upanishad warns
They who worship ignorance enter blind darkness. They who delight in knowledge enter darkness even deeper. It is different, they say, from knowledge.It is different, they say, from ignorance.
Modern science has found that to be true as well. Here is an amazing video of a hollow mask of chaplin's head. Watch it and see for yourselves that there is nothing you can do to stop the illusion your mind creates. Apparently you need to be schizophrenic to not fall for it.

Another example of an illusion your mind pulls off is the "Moon Illusion". Most of us have SEEN the moon to be bigger when it rises. The effect is really dramatic on full-moon days. You should get out and see it for yourselves. Have you ever considered the possibility that it is not so?

I can't help wondering if this is what the ancients meant when they talk about our senses deceiving us, or knowledge being limited in its use and can fail us in our quest for reality.

Thursday, January 21, 2010

speculations on extraterrestrial life...

There is a view that existence of life in other planets is almost a certainty. It is also very likely that two life forms in different planets end up communicating. Science fiction is full of stories where civilizations collaborate forming galactic federations. The characters in such novels end up being remarkable human like. I often wonder if it is possible for "human" like life showing up on other planets. It does seem rather reasonable to expect that "intelligent" species on other planets look dramatically different from us. Is it also reasonable to expect them to have eyes, ears, hands, legs, brains etc?

I'm of the view that it is indeed very reasonable to expect them to possess the faculties that humans and lot of other life forms on earth possess. My reasoning goes something like this. The big bang throws out a huge amount of energy. A fair part of it ended up being matter. These elementary particles ended up producing "elements". I think it is reasonable to expect other planets to have "matter" that is largely like the "matter" on earth. Solid, Liquid and Gaseous. The laws of Physics would ensure that Chemistry works much like it does on earth. An extension of Chemistry to Biology and origin of life on some planets is also inevitable and can be expected to occur very similar to how it did on earth. So, it is reasonable to expect that the laws of biology are also universal. Natural selection, I think, is a fundamental law of nature. I think it is very very reasonable to expect any intelligent life on other planets to be subject to the laws of natural selection. In short, I think the laws of physics, chemistry and biology ought to be universal.

Light exists everywhere. Life everywhere will evolve sight. Eyes are inevitable. Such a reasoning would almost extend to the sense faculties that we possess.

Locomotion would add survival value. Life everywhere would evolve legs. It seems reasonable to expect hands to follow. Bipedal life would evolve.

Life would evolve very much like it did on earth. Most intelligent life on earth does have hands, legs, brains etc. Is there any reason to expect things to be different on another planet? I think not.

My speculation is that if and when we find life elsewhere, it is going to be boringly similar to life on earth. Maybe pink plants and green men. That's about it.

BTW, blogging is apparently good for your mental health. Some more reason to keep typing.

Sunday, January 3, 2010

Genetic algorithms in the Design of Comparators - Part 2

This blog follows up on my previous blog on the use of Genetic Algorithms in the Design of Comparators. The basic mutation methods used earlier used only single gene mutations. The next generation is just derived from one "parent" with some "genes" changed. It is very easy to modify the process such that the new gene for any iteration is derived by combining the changes that were made in the previous generation that results in the two best "children".

Let C = F (X1, X2...Xn) be the cost function of the "comparator" where X1, X2 ...Xn are the genes. If the changes in genes Xi and Xj result in the two best comparators in an iteration, the evaluated cost function will be of the form

Ci = F (X1, X2, ..., Xi, ...Xn)
Cj = F (X1, X2, ..., Xj, ...Xn)

In the previous method, I would have just used (X1, X2, ..., Xi, ...Xn) as the base gene for the next iteration. I could very easily change that to use to two best genes and use (X1, X2, ..., Xi, .., Xj, ...Xn). It also makes sense to evaluate the "base" in each iteration since it is new.

One can expect the effect of the two genes to "superpose" and result in a larger improvement than each individually. This need not happen in all iterations though. One might expect such a process to produce improvements in the design faster than the previous method. I don't think there is any reason to expect dramatically different "results" though.

Extensions that pick the top three best or more genes are also possible. I live on earth and not a para universe. Hence my preference for two.

A variant of the idea is to to pick up all "mutations" that result in an improvement from the "base" or "parent" gene in each iteration. Improvement is defined as the "cost function" evaluating to a value higher for the "child" than the "parent". Superposition principle would for the most part still apply and one can expect the next "gene" to be better than the previous one. I did notice that most of the "children" quickly end up being "not better" than the parent and very few changes actually improve the "cost function". I'm not sure if these methods are any better than the method that just selects the best in each iteration. It appears that "vanilla" natural selection performs just as efficiently as any "intelligent" variant of the idea. Maybe Intelligence has a lot less practical value than you think.

Another aspect of the two methods described here that make them different from the older method is that these methods can result in designs that are temporarily worse than the previous iteration. There is a possibility that the "mutations" that are being combined in one generation result in a worse cost function in the next. This is in contrast to the first method where the cost function can never reduce from one iteration to the next. The possibility of a temporary decline is a price one needs to pay for the possibility of faster increase in the cost function. Intelligence, invariably implies fallibility. The theory of natural selection, apparently, does not allow species to get worse temporarily. That might disqualify these methods from falling into the category of Genetic Algorithms. Maybe the biologists have some thing to think about. Can intelligent species temporarily decline?