Tuesday, December 30, 2008

Spicy!



I was having some very spicy food - So spicy that it was unblocking my sinuses [1]. I remembered that technically, 'spicy' is not a taste at all. The tongue has taste receptors for four basic tastes - Bitterness, Saltiness, Sourness and Sweetness [2] There is no specific taste receptor for Spicyness. [or hotness]

To repeat, the tongue has taste receptors which 'sense' the taste and pass on the information to our brain. But, there is no taste receptor for spiceness/hotness. The pain/temperature nerve-endings are used to transmit the spicy taste to our brain. This is what I meant when I said 'spiciness' is not technically a taste. 

Basically, some cells of the tongue literally burst when they enter into contact with spicy food. This pain is interpreted as spicy taste by the brain. In extreme cases, the tongue may even bleed while extremely spicy food is taken. When nature rebuilds these cells, it builds it even more stronger - So, it is tough to crack these cells again [3]. That's why, people get 'used' to spicy food. The food that was once very spicy doesnt seem that spicy after a couple of weeks. 

But, how do we measure spiciness of food? 

To measure spiciness of food, a special scale called 'Scoville scale' is used. This scale is based on the amount of 'capsaicin' which causes the spicy taste. This compound, is found in varied levels in different foods that we take. By measuring the amount of capsaicin, we can determine how spicy a food is. The unit of spiciness is 'Scoville units' 

The Habanero pepper of Latin America was considered the most spicy of all natural foods for a very long time. Recently, Naga Jolokia (or Bhoot Naga) pepper found in Assam and few other states of North-East India now holds the crown for the spiciest of all chillis (or peppers as they call it in the west) - The green chillis that we take are about 50,000 - 100,000 Scoville units spicy. Compare it with the spiciest Naga pepper which is about a million (1,000,000) Scoville Units spicy!!!! Recently, I read in a newspaper article that farmers found that Bhoot (Bhut) Jolokia peppers drive wild elephants away from crops.

According to Ayurveda, spicy foods have a pleasant 'after-taste' i.e, they leave a good feeling after having it.  So, go ahead and have some spicy food! 

Btw, if you hurt yourself with very spicy food, don't reach for that glass of water or a teaspoon of sugar! It will not help! Since capsaicin is a oil, you need something fatty to emulsify (break it down) - Do it with some cold milk / sugar, or even better - icecream! [Who said reading my blog may not be useful for practical purposes (he he)]

Btw, I wish all readers a very happy new year - 2009! I was travelling a lot over the past few days. I owe a travelogue - That is in works. You'll be seeing it shortly!

PS:-

[1] I dont have a sinus problem per se. Suffering from a bad bout of cold - Damn the virus!

[2] There is a new fifth taste identified as Umami. Indian system (also Japanese and Chinese) identify 6 basic tastes. 

[3] This is the same priciple behind weight training / resistance training while exercising. By lifting weights, the muscles undergo micro-tear. This is the cause of the mild pain / strain after exercise. After this micro-tear, the body builds it back stronger. So, after few weeks of exercise, you have stronger muscles. 


Monday, December 15, 2008

Limit of Perception



No experience is as humbling for me as sitting alone in front of the sea in a beach. I usually filter out the background noise and visuals and focus on the mighty ocean - I have been to a few beaches around the world, but nothing beats the local Chennai's Marina Beach. I usually have a lot of fun (also Bajji, Sundal) with my cousins, lose my car key etc. (and hope some friendly cousin would retrieve it in a zero probability act)

But, when I do go alone, I spend some time gazing at the mighty ocean. That's the time I let go of my bloated ego. I suddenly feel very small. It is more humbling to realize that the earth that has this mighty ocean is indeed a very small part of the solar system. For e.g., Jupiter is 1o times bigger (in diameter) and Sun 100 times (in diameter). All this Solar System is a tiny speck in the Milky Way. Btw, Milky Way is one of the many galaxies. So, the first thing I search after thinking about this is my ego. 

"How do we perceive this Universe?" is the grand question that came to my mind. Perception is a function of our senses. 

To get excited by the depth and size of the sea, I rely on my eyesight. The sea is much bigger than say, me. [1] I perceive the sea because of light. For e.g., if I went to see the sea only when it was pitch dark, I would not notice its grandness at all. And, our eyes are capable of perceiving only some wavelengths. For e.g., eyes cannot see Infra Red and Ultra Violet rays. 

What if our eyes could perceive these wavelengths reflect from the sea too? You might be able to sense the temperatures at different locations. That would give you an extra dimension of perception. For e.g, just by looking at a coffee tumbler, you might be able to say how hot it is. So, you'll agree that by just widening the range of the eyes, your perception of the Universe got a little wider.

I realized this strangely, in S. Korea. I was in Suwon, S. Korea for more time than I would have liked :-) - I had added problems of being a vegetarian, which definitely did not help. I used to see a lot of neon boards throughout Korea. When I say a lot, I mean a LOT of them.

These boards never made any sense, and never made it to my cognitive mind. Then, all of a sudden, I started learning Korean.  [2]

As soon as I started learning Korean, all the boards started screaming to me! All those that would remain silent and be filtered, suddenly started making sense to me! Each board was speaking to my mind. So, by learning Korean, my perception widened. 

Then in a similar manner like we argued for light, we can argue for sound too. The sounds human can hear are in the range of 20 Hz to 20,000 Hz. [3] - May be we can hear finer sounds, and a wider variety of sound if we increase the range of our hearing. [4]

So far, we talked about the senses we perceive - But what if there are senses that *NONE* of the humans can perceive? Are there any senses like that? Are we missing some splendid dimension of perception? Do we miss anything great, just like we feel that someone blind is missing out on great views? How would we know? 

Is the Universe much Grander than we perceive? 

The act of communication is based on predefined common grounds. For e.g., if you don't know what the word (or sound) 'One' means, you'll not understand if I say 'One' to you. [5]. If there is no common ground, there is no way to communicate. So, is this the reason why great Saints who were One with God, couldn't put it in words what the experience would be. One thing that I find common among a lot of relegions is that once they try to define God, they try to negate what He is not - Most probably, it would be like "Formless, Attributeless...." - The Vedic way of finding God is negating all that He is not by saying Not This, Not This (Neti, Neti) - Can this be the reason why we cannot define the Grandness of the God Concept? May be the Yogis and Saints have a much wider sense of Perception that we cannot even imagine? 



PS:-
The picture is from http://www.intelligentuniverse.org

[1] Some people may claim it is not much bigger - grrr

[2] Some people may find it co-incidental that I made friends with one lovely lady in a Sandwich shop around the same time. She could speak only Korean. 

[3] I am reminded of a tamil dialog - "Ungalukku Kaathu Konjam Kaekkatha? Illai Konjam Kooda Kaekkatha?" by Koundamani, I guess. 

[4] If the frequency is sufficiently high, we can let go of radio stations and tune to different stations by our ear! Or may be we can move around with our eyes closed, just like bats. 

[5] You may know other languages and may relate - Ondru in Tamil (Onnu in slang) could sound similar to 'One' in English - Why does English sound so close to Tamil/Sanskrit :-)
One     - Ondru / Onnu [Tamil]
Two     - Dwi 
Three  - Thra
Four    - Chathur / Naalu[Tamil]
Six       - Shash
Seven  - Sapta
Eight   - Ettu (Tamil) / Ashta
Nine    - Nava
Ten     - Dasha


Saturday, December 06, 2008

Being 'Good' is not tough!



I was thinking that being good is not tough at all! When I mean good, I mean being good at things. But, being great is very tough. 

For e.g., some one can be good in singing. He may be able sing significantly better than a large percentage of the population. May be he is better than 90% of the world population. But, he may not even dream of competing with someone like Sanjay Subrahmanyam or G.N.B [1]. This is what I mean by it being good is not tough, but being great is. To reach to the top 0.01% takes significantly large effort than reaching the top 10%. When I say significantly large, I mean the effort is in order of 100s or 1000s.

Then there are people who are insanely great - The Genius stuff. They simply blow me away. Almost their entire persona is resonating with the frequency of what they want to achieve. Though they appear to exist in this world, they don't. They may jump up suddenly with a sudden glimpse of something extraordinary. They have solved a problem that many couldn't. 

I don't want you to mistake the problems these insanely great people solve. These problems cannot be solved by a crowd - Adding more people to solve these genre of problems doesn't help. You'll need the help of a crack genius to solve whacky problems. A group of million regular people in thought cannot have the breakthroughs Einstein had to establish Special and General theory of relativity. 

I remember a Bond movie, Golden Eye, I think, where one of the bad guys asks another bad guy - 'Why did you get this guy to build this gun? This guy is insane' - The other bad guy replies - 'Sane people don't build such machines'

The Genius domain has always puzzled me. I always wish, hope and pray that I could have a glimpse of the domain, however brief it may be. 

In a talk You and your Research, Hamming talks about how these Genius people work, and even how to get there! Please check it out when you have time. You'll thank me for it. The key is to work harder and harder. When I had just joined Philips, I worked with an excellent Architect, who used to tell me - 'Sriram, the key is to work very hard. You have to keep churning, however hard it might be. You have to persevere. At the end, the Amrit (Elixir of Life) has to come' [He was talking about the mythology where a milk ocean (Ksheera Sagara) had to be churned to get Amrit that would bestow immortality to people who would drink it]

Einstein said 'Genius is 99% perspiration and 1% inspiration' - This may be true. But I have seen few genius guys crack some serious stuff with zero effort. May be it is the result of hardwork they put in earlier. I'll never know. But, it is truly possible to be insanely great by hardwork alone. The key is to avoid distractions and have focus. [I'll talk about focus and how I learnt its importance from one person I greatly admire and respect in a future post.]

In the end, it is one's choice to be bad, good or great. All I wanted to do was to prod people in the 'good' category to try and move to the 'great' or 'insanely great' category. Satisfaction is not a virtue sometimes :-)

PS:- 
The picture in the beginning is a photo of Einstein's Black Board (http://www.mhs.ox.ac.uk/blackboard/images/einstein-l.jpg)

[1] My knowledge is limited to Carnatic Music (Indian). Please replace the names by Stalwarts and Genius in the genre of music you like. 

Friday, December 05, 2008

Pedestrian

I was riding by the new Airport Road (Bangalore, just before Hebbal flyover)- I saw an old couple trying to cross the road. I was deeply pained to see callous attitude of drivers who seem to whizz past by and not stop for the old couple. I was furious with the planning authorities for their abject lack of vision. Inarguably, India is the WORST place for pedestrians. They are the pariahs on the road - Least respected and cared. It only gets worse in Bangalore. I realized it even in my first week here (about 8 years ago). I was crossing the road by a turn and a car was approaching. I thought the driver would slow down and kept walking in my pace. In a moment I realized that the car driver had no idea to slowdown, and I had to literally jump off the path of the car to avoid getting injured. I thank God that I was physically fitter that time - I would have mutely submitted to the will of the driver and God now :-) 

As I was thinking of the plight of pedestrians in Bangalore and India in general, I realized that the word 'pedestrian' is a very interesting word. 

The word pedestrian means, 'of the foot' (ped / pes -> Latin for foot) - One who travels by foot. [One who travels by horse is equestrian where eques means horse]

This is the noun form of the word pedestrian. There is also an adjective form of the same word. Here 'pedestrian' means unimaginative or very ordinary. 

For e.g. 'The furniture on the display was pedestrian'

I was wondering if the adjective form of the word is also being applied the noun form, where status of pedestrians in India is pedestrian! [1] 

The root 'ped' is widely used - For e.g., we are called bipeds,  those who walk on two legs, assuming quadriped aliens are not  reading my blog. 

Centipede is an insect which works on 100 (centi) legs. I haven't counted, but 100 used to be a large number for ancients - So, an insect with lots of legs could be called a centipede. In India lots of ancient scriptures use the number thousand to indicate a huge number or something too large to count. For e.g., in Purusha Suktam, God is supposed to have 1000 eyes and 1000 feet [2] 

The root 'ped' also comes in millipede,  impede etc. Pedal is one that you press with your leg. Moped is one which uses a 'Motor' to assist you 'Pedal'

The word expedite means 'to prepare'  or 'to make things faster' - It is derived from to remove chain from the leg. Military 'expedition' means 'to cover areas faster by military'. 

So, next time when you see a 'ped' in an English word, you know how to take a good guess at the meaning :-)  



End Notes:
[1] I know it is an exceptionally bad use of the adjective form, but I am just trying to be imaginative

[2] Sahasra-aksha sahasra-pad [Sahasram -> Thousand, Aksha - Eyes, Pad -> Feet]

Sunday, November 30, 2008

Sieve of Eratosthenes

This is a famous algorithm, typically used for generating prime numbers from 1 to N.

This algorithm is attributed to Eratosthenes, a Greek Mathematician who lived around 200 B.C. - I have described the algorithm and how it works:

A non-zero, postive integer (natural number) is prime if it has no other factors other than 1 and itself. 1 is neither prime nor composite. And 2 is the only even-prime number. 

So, multiples of 2 cannot be prime (they have 2 as one of their factors) - Similarly, multiples of 3 also cannot be prime. And so on. So, the idea is multiples of a number cannot be prime. 

So, let's consider numbers 1 to 100. 

Create an array of 100 numbers and set them all to 1. 

Let's start from 2 and mark all the multiples of 2 till 100 as non-prime (a.k.a composite). To do this, let's set the value in the array as 0.  [The index should go till 100 / 2]

Then, let's start with 3, and again mark all the multiples of 3 till 100 as non-prime. 

Next you reach 4. But, this is 0 already. So, the multiples of 4 should already be set to 0. (Since all multiples of 4 are already multiples of 2) - So ignore 4. [And ignore multiples of those numbers which are already marked as 0]. Then start with 5.  

So, how far should you go? Some people choose to go till N / 2 (50) - But this is sub-optimal. It is sufficient if we check for all multiples till square root of N. This is because, any factor greater than SQRT(N)  should have a partner that is less than SQRT(N) and hence would have already been marked 0. [Please re-read this para-graph :-) if this sounds confusing]

Now iterate through the array and print all indices where the value is non-zero. Voila! You have generated prime-numbers in O(nloglogn). 

I wrote an implementation in Python. It was quite cool :o)

#!/usr/bin/env python
# eratosthenes.py
# Sriram V Iyer
#
# Implements the eratosthenes sieve program

# Initialize an array for 100(+1) 1s
# +1 is to accomodate the cases 2 * 50, ...
l = [ 1 for i in range( 100+1) ]

# make the multiples as 0
[ l.__setitem__(i*j, 0) for i in range(2,10) for j in range(2,(100/i)+1) if l[i] != 0 ]

# print indices of the list that are still 1
print [ i for i in range(2,100) if l[i] == 1 ]

I had a discussion with Tejaswi (my Beceem colleague) on an equivalent C code.

Btw, I used the C/C++ compiler feature that initializes unitialized elements of a a partially initialized array to 0. This way, I changed the polarity to 0 -> Prime and 1 -> Composite in the C code. [This way, I needn't write code to initialize the array to 0]

/*
    eratos.c
    
    Sieve of Etatosthenes in C/C++
*/
#include "stdio.h"
#include "math.h"

int main()
{
    int N = 100, i = 0, j = 0;
    int nArray[100+1] = { 0 };

    for( i = 2; i < (sqrt((double)N)); i++ ) {
        if(nArray[i] == 1) continue;
        
        for( j = 2; j <= (N/i); j += 1 ) 
            nArray[i * j] = 1;
    }
    
    for( i = 2; i <>
        if(!nArray[i]) printf( "%d ", i );
    }
}

There is one more possible optimization - If you can initialize nArray[4] = 1 in the code before the first loop, you can start the inner loop from 3 :-)

PS:- Looks like the "<<" in cout can confuse blogger. So, I rewrote the program without using cout, endl :-)

Thursday, November 27, 2008

Sri Krishna


There are regular people, and then there are people who test the limits. 

As for as this Universe is concerned, (with no offense to anyone else), the limit with which Divinity can express in a form, IMHO is Sri Krishna. 

Ishwarah Paramah Krishna:
Satchidananda Vigrah: |
An-Adir Adir Govindah:
Sarva Kaarana Kaaranam ||

Limit of Divinity is Krishna
He is Absolute 'Truth - Consciousness - Bliss' in Form
He is Govinda, One without Beginning or End
He is The Cause of all Causes.

Law of Karma or even the Third Law of Newton says Every Action has a cause. (An action is a reaction to some event)  - When you keep tracing back, everything traces back to the Initial Cause - This Cause is Sri Krishna. 

People who are exposed to Carnatic music will know that when the pitch of the tones increase, it is called 'Aarohanam' and when it decreases, it is 'Ava'rohanam. So when the Unknown Divine, decides to 'Come Down', it is called an 'Avatar'. Avatar is now an English word, which means 'Another form' - But this is not technically the true sense of the word. To take an Avatar means, to step down (or) descend to a Form. 

Sri Krishna was a Purna Avatar - i.e. A complete Avatar. He took His Form with all His Original Glories. When such an Avatar is around, miracles are a daily event. 

I have always wondered how it would feel to be Sri Krishna - Absolute Power with No restraints. 

Whenever Sachin Tendulkar is at the crease, batting, I see every ball with trepidation. I am afraid if he would be out. He is truly a Hero, but fear is there in my mind.

However, if there is one hero whom I can count on to succeed everytime, it should be Sri Krishna. He simply never loses or fails.

Whenever I get time, I'll try to reflect on His Life, His Teachings. They have brought solace to me whenever I was in trouble - It should undoubtedly help you too! 

Sarvam Sri Krishnarpanamastu!



 

Wednesday, November 26, 2008

Space, time and relativity - Part 3

I really should be sleeping now :-) - But, I thought I'd write this part and then go to sleep. 

I should call this part - 'Illusion of Time' 

I said space and time varies whenever you move. (There are other questions like how do you define 'not moving' :-) - For e.g., I could be sitting in a couch but am moving very fast along with earth! But these questions, I'll save for later or leave it to you for pondering - What is meant by absolute rest?)

How does time vary with speed? Actually, time slows for the person who is traveling. As I have mentioned before, if you have two accurate stop clocks with a huge resolution, and you decide to go around travelling while your friend stands still, when you meet him again, you'll definitely find that you spent less 'time' - i.e., your stop watch will show less time than your friend who is standing! [I find this result so amazing and unbelievable!]

I don't want to get into the math of how time varies when you start moving. (Not that I remember it well :-) ) - For the object / person moving at the speed of light, time stands still. i.e. If you are traveling at light-speed your stopclock will stop ticking while your friend's will be ticking in all glory!

I want you to imagine how it feels when your time stops. Only yours. 

Assume you are going around the earth in light speed - For people and animals on earth, time keeps passing. Time flows from the past, to the present and to the future. For you, time doesn't pass. You keep staring at people being born, living and finally, kicking the Holy Bucket. While these events seem to be separated by time for those people, for you, all these things happen at the same time! You see people's past, present and future all at once. 

For you, every 'event' (if I can call it so) happens in the 'Now' - There is no past nor future for you. Only Presence. How can you not know the past nor the present nor the future, since you are seeing it *ALWAYS*?

You'll seem to know everything - Right from when I'll get my Audi R8 to Sachin Tendulkar's cricket record when he retires in the future. You'll know how I fell into a gutter few days ago and how I felt happy when no one noticed! My (and everyone's) past and future are your Presence. (Present Tense)

You will concur with Mandukya Upanishad when it thunders in its first verse that God is beyond Past, Present and Future. 

As you slow down, time seems to catch up with you. When you think you've traveled for hardly a second, when you land back in earth, it is 29000 AD. Almost 27000 years since you left. You have no friend and there are strange structures in places where your house and your garden stood. 

You really get frustrated and decide to go back to watching things. You decide to become The Witness.

You go back to traveling at light speed. You are One with God. You are God.

-------------------------------- The End ------------------------------

PS:- That is the end of the revelation I got last Friday midnight while thinking about Einstein's Special Theory of relativity. For people who give a sigh of relief, I'll want to tell you that this is the end of the revelation and not my writing :-) - You have more to grieve

As appendix, I'll write more - Esp on How almost entire Hindu and Buddhist Philosophy can fit into this, along with teachings of the current Masters like Eckhart Tolle. If you think only Time is an illusion, I'll be glad to update you that 'Space' is also an Illusion :-) [Appendix - I] - 

After this series, I'll try not to go to Philosophy and stick to Physics and Maths (I'll try my best, but, you know, I can't promise that!)

Btw, I have '0' comments in my blog - THAT'S TRUE! Not a single comment for any of my articles! So, please pass on your esteemed comments :-)  - Otherwise, I'll keep writing!


Monday, November 24, 2008

Space, time and relativity - Part 2

Last time we discussed, Einstein concluded that space and time are not absolute, thus throwing away long held and cherished results of Sir Isaac Newton. 

Light was studied in detail by Maxwell who established the speed of light as 300,000 km/sec. But this speed is with respect to whom (or what)? Whatever the reference point is, light's speed is always same! 

Speed is defined as distance travelled divided by time. Since light's speed is constant irrespective of the speed of the observer, Einstein concluded that notion of time and space is different for different observers!

To explain this further, let us use an example. 

You ask your dear friend to moderate an experiment. You decide to race with light using your super vehicle (let's call it 'Viman') - You get on your vehicle and rush at 100,000 km/s and the light rushes out at 300,000 km/s

Your friend sees light moving 300,000 km every second, while you move 100,000 km every second. So, he thinks you must be seeing light moving at 200,000 km/second. When the race is stopped after some time, your friend checks with you, and you are totally disappointed. Howmuch ever you try, even reaching a speed of 200,000 km /s, light continues at the same 300,000 km/s

This is because, your notion of distance and time is different from the notion of distance and time from the point of view of the stationary observer. 

Since speed of light is constant irrespective of the speed of the observer, the great Einstein concluded that space and time are not fixed but are relative to that of the observer.

The speeds that we move in this world are not comparable to speed of light at all. The fastest rocket, EVER had a top speed of 3km/s. So, in this world, we are not able to observe the difference in  space and time. If you were able to move in speeds that are comparable to speed of light, then you'll be able to see the difference in space and time. 

For e.g., if you take a stop-clock in your hand and rush out at say 1/10 the speed of light. Your friend is standing in the same place and uses a different stop-clock. When you return and check your time, you'll be surprised that your clock shows less time has passed compared to your friend's!!!

Who is correct? The answer is both are! This is because space and time are relative. 

Contrary to popular opinion, Einstein did not want his theory to be called 'Theory of Relativity' - He wanted it to be called 'Theory of Invariance (of space-time)'

I think by the next installment, I'll be able to conclude with my paradox - It is not a paradox really! Just to whet your appetite, I am going to describe how the whole creation stuff would appear to God, and why he is Omniscient and why He *HAS* to travel at light speed only. (Any thing less, he loses his Omniscience!)

It has been a great feeling to imagine how God sees the whole stuff happening. It should be an exhilarating feeling for God! And, I can relate to numerous texts (Mandukya Upanishad, Sri Yoga Vashishta, A New Earth, Tripura Rahasyam etc) - I'll quote from these on Installment 3 or 4 and compare to this theory of relativity. 

It also explains why I like speed :-) - Any point of time, I put all my money in the fastest possible vehicle that I can afford at that time (comfort next!) - Getting to higher speeds, means I am getting closer to God!

PS:-
People who don't like philosophy please skip the postscript!
(1) I don't mean to be arrogant when I say if God travels at speed less than light, he cannot be Omniscient. It is just a side effect of the conditions that I have spoken about. Someone said 'God Defined is God Defiled' - God cannot be defined by words, thoughts, pictures or any other human medium of communication. 
(2) People who want to get closer to God are advised to buy their own R-15 and not borrow mine. :-) [By meaning closer to God does not mean or imply getting closer to Mr. Yama Dharmaraj :-D


Friday, November 21, 2008

Space, time and relativity - Part 1

I should have probably called it space-time and relativity, but, even 'Space, time and relativity' should be ok :-) 

For people who are new to the subject, I'd like to give a small intro before before we discuss the details...


According to Sir Isaac Newton, space is absolute. i.e., irrespective of the observer, space exists. 

To make this statement more clear, consider two places - Chennai and Bangalore.  Also consider the following dialog

Dialog #1
Me: What is the distance between Chennai and Bangalore?
Newton: 350 kms
Me: Thanks a ton.

Life becomes more complicated with Einstein...

Dialog #2
Me: What is the distance between Chennai and Bangalore?
Einstein: For whom?
Me: Holy crap!

In a Newtonian world, space is absolute. For Newton, distance between Chennai and Bangalore is same irrespective of who measures it. 

It is not so for Einstein. For him, Space and Time are relative. For an observer who is travelling at a good speed, the distance will appear less! The difference in the distance observed between a stationary and mobile observer will be more as one of the observers travels closer to speed of light (300,000 kms per sec)

Einstein published this result in 'Special Theory of Relativity'. This was a direct inference of his result that ‘Speed of light is constant irrespective of the speed of the observer’ 

For people who are not surprised by my previous paragraph, I would like to explain it further. 

Consider that a train is moving towards you at 50 kms/hour. The first thing you should do is to get off the track (he he)

Joke apart, consider you are feeling suicidal (which you shouldn’t) and standing on the track with train approaching you at 50 kmph. You’ll see that the train is approaching you at 50 kmph. 

If you are anxious to meet Mr. Yama Dharmaraj, you can choose to run towards the train, at say 10 kmph (the best I can do :-) ), the train will appear to come to you at 60 kmph. 

Suppose a dog starts chasing you, and you start running away from the train at 20 kmph, it will appear that the train is approaching you at  30 kmph. 

So far so good. Now, since you understand this, you got happy and jumped off the track and the dog got ran over by the train. Lets get back to Physics.

Now, you decide to chase light. Mr. Light Bheem is traveling at 300,000 km/sec. You decide to get on your super vehicle, and chase it at 100,000 km/sec [The fastest rocket on earth travels at less than 3 km/sec - You can now guess how fast light is!]

Since you are chasing Mr. Light Bheem at 100,000 km/sec, you expect his speed to be 200,000 km/sec (300,000 – 100,000). When you measure the speed of Mr. Light Bheem, you find that his speed is still 300,000 km/sec!!!! 

You get frustrated and increase your speed to 200,000 km/sec. And then you measure light’s speed – It is still 300,000 km/sec. You finally decide to give up and go back to railway track. You measure the speed for light for one last time after stopping your super vehicle. It is still 300,000 km/sec.

So, whatever the speed of the observer might be, the speed of light is Holy Constant. 

This observation led Einstein to derive that space and time are not absolute. 

I’ll explain more on Einstein’s conclusion next time… I have to step out now. 

Comments are welcome!


Monday, September 22, 2008

range vs xrange

In Python, you can create a list of numbers (arithmetic progression) using range( )

>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(5, 10)
[5, 6, 7, 8, 9]
>>> range( 2, 10, 2)
[2, 4, 6, 8]

>>> type(range(10))

range() returns a list of numbers - We may not need an explicit list for most of our purposes - We may require only one item of the list at any point of time for typical applications -

for i in range(10):
print i

While executing the above code, the call to range(10) creates a list with elements [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Then, i iterates over this list. However, creating the list this takes up memory, which is not actually required.

We can use a generator based method xrange() - xrange can be used instead of range in most applications where you do not require all the elements to be in memory.

for i in xrange(10):
print i

This code will behave identical to the previous version of the code that uses range(10) - However, memory is saved since it uses a generator based approach than creating the whole list in memory.

You can check that it does not produce the entire list:
>>> type(xrange(10))


xrange is an iterable container, that returns only the next element in the list. So, whenever you don't need the entire list in memory, go ahead use xrange() and save some memory :-)


Monday, September 08, 2008

A joke called Project6xn - Nokia N96


When Apple was launching its iPhone, Nokia decided to steal its thunder - They prelaunched Nokia N96! Wow! What a great strategy! 

The only problem is that I dont understand what a pre-launch means - Does it mean you release photos / specs of a product? Or show a dummy of the product? 

I think what it all meant was to tell people not to burn their hard earned money over iPhone (which I think is right way of thinking considering it has a 2 MP camera, and you cannot take videos, and cannot forward a picture over Bluetooth to your friend) - And no.. you cannot send MMS to your friend too - Please send your photo as an email - Thank you!

Coming back to Nokia N96, they decided to launch a webpage that would grab the attention of high end mobile users! Enter - www.project6xn.com. You have to register as a new detective, and after verifying your email, you can do something. (Btw, I never got through email verification - And yes, I checked my bulk mail folder!)

Then there was a couple of days for launch.. (By Aug mid) - I was pretty excited! And, on the D day, the website showed 7 more days (unless the website went through a worm hole and time warped, it couldn't gain time!) - A few more days later, believe me it showed 10 days more to launch!

I couldnt contain my excitement! Time was flowing in the opposite direction! (I now know that the total entropy of the Universe was decreasing, since the time is supposed to flow from a low entropy to high entropy state. I am surprised major cosmologists have not noticed it)

And then, when the project slipped further, the time became negative. Please look at the screenshot above.

The first stanza of Mandukya Upanishad says - 'Om is everything. Om is Past, Present and Future. It is also beyond all these three'. (How can something not be in one of Past / Present / Future? The Upanishad hints that for the Almighty, time is nothing a but one of multitude of dimensions, and hence time does not define 'Om' completely)

I am severely moved by this Nokia website competing with Om for it truly transcends time (I am getting emotional here)

Nokia! For HEAVEN'S SAKE stop this joke. And remove the website. It is all but an eye sore. (I am sure I shouldn't be doing this.. but let me quickly check the website if the phone has launched... 

Holy Crap! @#@$#$$#%$%^$ )




Tuesday, September 02, 2008

Google Chrome!

I just happened to stumble across the Google Chrome comics
http://www.google.com/googlebooks/chrome/#

And also the official Google blog entry:
http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html

Boy, am I excited!!! Based on the comic, I can see that Google is taking the browser in the right direction. It may stand to benefit from the whole stuff, but still!

I think google's idea of using popular ideas of computer operating systems in a browser is pretty cool. What we get is time tested techniques in a new platform (browser). None of the ideas are like earth-shatteringly new, but it makes a real innovative mind (or lots of them) to come up with a new browser grounds up like this! Javascript VM implementation that compiles to native in the browser, is quite radical though.

It takes great guts and spirit to open source the entire browser and the entirely new V8 Javascript .

Google Chrome is not available for download (yet), but going by what is there in the comic, I think this a great step forward for the entire web programming domain as a whole! I'll sure check it out tomorrow, when it launches!

Hats off, Google!

Wednesday, August 06, 2008

Getting assembly listing embedded with C/C++ Source Code using GCC

I was planning to look at some odd behavior of C++ typedefs and assembly output in the case of GCC/G++ compiler suite for MIPS, especially when O2 optimizations were used.

For most of the compiler suites (Borland, GCC) one can generate the assembly listing by using -S option.

For e.g., if you have file called foo.cpp, then you can see the assembly equivalent by passing -S as an argument to the compiler (Remember that it will not produce the .o / .exe output as usual)
c:\Sriram:\> bcc -S foo.cpp
c:\Sriram:\> mips-elf-gcc.exe -S foo.cpp
This would produce a foo.asm or foo.s output containing the assembly listing in the same folder.

However, I wanted to embed the C/C++ source code for mips-elf-gcc along with the assembly output for easier debug. After looking at many compiler options and googling, I found the mix I need:
c:\Sriram:\> mips-elf-gcc.exe -c -g -Wa,-a,-ad foo.cpp
You might note that I did not include the -S option!

The options are as follows:
-c : Compile only (dont proceed to link - This is because foo.cpp did not have a 'main' or equivalent.
-g :Include debug informaiton
-Wa : Pass the following options (comma seperated to the assembler)
-a : Include high-level, assembly, and symbols listing
-ad : Omit debugging pseudo-ops from the listing

Please look at GCC Documentation and a GNU Assembler Documentation for more information.

Saturday, August 02, 2008

Ruby! (sqlite3 and Ruby on Rails)

I have been programming in Python for a while - To say 'programming' is a bit staid - I love python and I keep writing scripts just for the heck of it.

Of late, thanks to popularity of Ruby on Rails, I thought I'd learn Ruby - I started Ruby a week ago, and thanks to my super work-schedule, I haven't been able to spend a lot of time. But, since I already know python, it might be easier to learn Ruby.

I'll write more on how I feel Ruby is, and how it compares with Python as time goes.

To warm up on Rails, I got the book "Ruby on Rails - Up and Running" - I installed RoR using gems
c:\Sriram:\>gem install rails

Then when I started the server, and created the first controller (Greeting in the book) mentioned in the first chapter, I got the following error:

"no such file to load -- sqlite3"

[This error message appears in the web-page when I tried to load "http://localhost:3000/greeting"]

It has been a while since I did some web-programming. I panicked for a moment, but reassured myself that this problem should be trivial, and it was :-) (Yad Bhavam, Tad Bhavati [As you think so will it become])

I realised that I need to install sqlite - The database that was default in RoR. So, I went to sqlite download page , and downloaded the command line and the dll. (make sure the versions of the dll and the command line match to avoid surprises later) - I downloaded sqlite-3_5_9.zip and sqlitedll-3_5_9.zip. I unzipped the dll and copied it to c:\windows\system32

Then I also installed sqlite3-ruby
c:\Sriram\Rails:\>gems install -r sqlite3-ruby

I then restarted the WEBrick server and voila! I could see the rendering of the text in index function of the controller in the web-page.

FYI, I am running on a quad-core PC with Windows Vista. Ruby 1.86. RoR 2.1

Btw, I downloaded the 'Instant Rails Package' - I have been trying to unzip the package for the past few hours. Looks like it is easier to get going with the gems installation of RoR and manual install of sqlite3 (Instant Rails may be more useful for a bigger project, but to get your hands wet, the above steps should do...)