31 January, 2010

Think 0÷0 =?


One day a teacher was explaining about basic mathematics to his pupils. He posed the following question,

"I have 25 apples with me, and you are all total of 25 children. So, if I distribute them, how many apples will each have got"?

The children shouted in chorus "one apple each".

A smart boy erected up, and question the teacher "there are no children in the class and you don't have any apples, even then would we able to get one apple each"?

The teacher was puzzled for a while. Then the teacher said 'I don't know my boy'.

The student intent was, when 1÷1 = 1, 2÷2 = 1, so on... will 0÷0 equals to 1? And later the student proved that 0÷0 is NOT equal to 1.

The student was none other than SRINIVAS RAMANUJAN, a mathematical genius till now world had. Unfortunately our land lost him at early age.

If possible read the book THE MAN WHO KNEW INFINITY.

28 January, 2010

PI (∏) = 3.14.... ?

How to prove the value of PI is constant and irrational number? Here is simple proof.

Yet to update, need some diagrams.

05 April, 2009

Role of Type System in Software Development (Technical)

If some one asks what is C++, I would say better C with primary emphasis on type safety. So what is the significance of "Type System" in program development? I will try to explain...
During implementation of software, programmers usually overlook warnings thrown by the compilers that are against to the usual conversion rules. Unfortunately programmers will tend to suppress forcibly few warnings. A sort of type overriding will cause critical errors. Let us analyze two such kinds of idioms.

Brief Description of Type System
A type is set of values and associated operations, where as an Abstract Data Type represents generic mathematical model. An ADT will have its own definition in each programming language. For example the 'int' is a primitive type defined by compiler which allows addition, subtraction, multiplication and division on such variables. When an 'int' type is mixed with scalar variables (e.g. pointers) the kind of operations will be different, like pointer addition and subtraction. (multiplication and division are not valid) And, present day compilers are providing user defined operations on any of data type with the help of operator overloading.

Enumerations in C and C++
In C the enumeration constants (like INACTIVE given below, not enum variable) are just integers or can be converted to integers easily. After one or two stages of parsing, the compiler replaces the enumerated constants with their equivalent integer representations. And hence assignment of integer to enumerated type variable is a valid programming construct.

In C++, even though the literal INACTIVE is constant, it will have an associated type information during parsing. And an implicit conversion of a user defined type (like enum) to another type (like int) is not allowed. This will help us in making better software.

How the type system will help us?
As an example, observe the following code snippet,

typedef enum SystemStateTag
{
INACTIVE = 0,
OPERATIONAL,
FAILURE
} SystemState;

Snippet1

The type SystemState represents state of a system in enumerated constants INACTIVE, OPERATIONAL and FAILURE. The compiler imposes enumeration type on any SystemState variable. Let us analyze the following code in terms of C and C++ compilation.

int calculateState();
SystemState sysState = calculateState();

In the above statement, the assignment

sysState = calculateState();

causes an implicit or explicit conversion of int to enum based on the type of compiler used.

As per ANSI C, the conversion from an int to enum is valid and implicit (no need of casting), and as per ANSI C++ the conversion is an error, requires an explicit casting. Some compilers (e.g. Borland C++ 5.02) treat the conversion as warning by default, and generates error message when compiled as per ANSI standard (try using –A option in Borland).

Since we are assigning the return value of function calculateState() to sysState, it is possible that the function may return values other than 0 (INACTIVE), 1 (OPERATIONAL) or 2 (FAILURE), in which case the system will be malfunctioning.

Perhaps this error would be trapped during system testing time and at this stage the correction effort will be more. By imposing C++ strict compiler type checking we can push such errors to compile time. In C, using defensive programming designs, like use of switch cases along with default statement, we can catch such errors at run time, but it would be too late.

Errors due to implicit conversions
The following code compares sysState against OPERATIONAL and the result is of type Boolean (can be of 0 or 1).

if(OPERATIONAL == sysState)
{
// process command
}
Snippet2

If the programmer tends to compare as shown below, is valid in C or C++

if(sysState = OPERATIONAL)
{
// process command
}
Snippet3

A C/C++ compiler implicitly converts ‘the return value of assignment statement (What it mean?)’ in ’if’ to Boolean type. It is the limitation of C++ to support legacy code written in C, it can be made fail safe by using defensive programming idioms as shown in the snippet2, because the statement OPERATIONAL = sysState is not valid in C/C++. This was an error that caused loss of $400 million during space craft take off.

Modern programming languages like C# imposes strict type checking, and will not allow any implicit conversions. Code snippet3 will not be allowed in C# or Java.
Especially Engineers making safety critical systems need to be aware of in depth knowledge in type system.

04 April, 2009

Utility Theory

Have you ever thought what will happen if the currency value falls or raises? What is the importance of Economics?
(Yet to Update :))

18 February, 2009

No One Perfect, Quarrels are Natural

18th Feb, 2009

Ohh.. After exactly an year, posting new message…

I received the following mail message from my friend, something to learn from it… just go through

Monica married Hitesh this day. At the end of the wedding party,
Monica's mother gave her a newly opened bank saving passbook.
With Rs.1000 deposit amount.

Mother: 'Monica, take this passbook. Keep it as a record of your marriage life.

When there's something happy and memorable happened in your new life,
Put some money in. Write down what it's about next to the line.
The more memorable the event is, the more money you can put in.
I've done the first one for you today. Do the same with Hitesh.
When you look back after years, you can know how much happiness you've had.'

Monica shared this with Hitesh when getting home.
They both thought it was a great idea and were anxious to know when the second deposit can be made.

This was what they did after certain time:

  • 7 Feb: Rs.100, first birthday celebration for Hitesh after marriage
  • 1 Mar: Rs.300, salary raise for Monica
  • 20 Mar: Rs.200, vacation trip to Bali
  • 15 Apr: Rs.2000, Monica got pregnant
  • 1 Jun: Rs.1000, Hitesh got promoted
..... and so on...

However, after years, they started fighting and arguing for trivial things.
They didn't talk much. They regretted that they had married the most nasty people in the world....
No more love...Kind of typical nowadays, huh?
One day Monica talked to her Mother:

'Mom, we can't stand it anymore. We agree to divorce. I can't imagine how I decided to marry this guy!!!'

Mother: 'Sure, girl, that's no big deal. Just do whatever you want if you really can't stand it. But before that, do one thing first. Remember the saving passbook I gave you on your wedding day? Take out all money and spend it first. You shouldn't keep any record of such a poor marriage.'

Monica thought it was true. So she went to the bank, waiting at the queue and planning to cancel the account.

While she was waiting, she took a look at the passbook record. She looked, and looked, and looked. Then the memory of all the previous joy and happiness just came up her mind. Her eyes were then filled with tears. She left and went home.

When she was home, she handed the passbook to Hitesh, asked him to spend the money before getting divorce. The next day, Hitesh gave the passbook back to Monica. She found a new deposit of Rs.5000. And a line next to the record:

'This is the day I notice how much I've loved you thru out all these years. How much happiness you've brought me.'

They hugged and cried, putting the passbook back to the safe.
Do you know how much money they had saved when they retired? I did not ask. I believe the money did not matter any more after they had gone thru all the good years in their life.

"When you fall, in any way, Don't see the place where you fell, Instead see the place from where you slipped.

“No one perfect, accept your partner as they are. There is no ABSOLUTE"

18 February, 2008

Five Monkeys Experiment (Change Management)

There was an interesting experiment that started with five monkeys in a cage. A banana hung inside the cage with a set of steps placed underneath it. After a while, a monkey went to the steps and started to climb towards the banana, but when he touched the steps, he set off a spray that soaked all the other monkeys with cold water. Another monkey tried to reach the banana with the same result. It didn't take long for the monkeys to learn that the best way to stay dry was to prevent any monkey from attempting to reach the banana.


The next stage of the experiment was to remove the spray from the cage and to replace one of the monkeys with a new one. Of course, the new monkey saw the banana and went over to climb the steps. To his horror, the other monkeys attacked him. After another attempt, he learnt that if he touched the steps, he would be assaulted.

Next, another of the original five was replaced with a new monkey. The newcomer went to the steps and was attacked. The previous newcomer joined in the attack with enthusiasm!
Then, a third monkey was replaced with a new one and then a fourth. Every time a newcomer approached the steps, he was attacked. Most of the monkeys beating him had no idea why they were not allowed to climb the steps or why they were joining in the beating of the newest monkey.

After replacing the fifth monkey, none of the monkeys had ever been sprayed with water. Still, no monkey ever approached the steps. Why not? Because as far as they knew it was the way it had always been done around here... and that is how company policy begins.


People usually reluctant to change their ways (their thoughts)
Courtesy - http://www.mwls.co.uk/anecdotes/alphadex.htm You can find more articles here.

11 January, 2008

90/10 Principle of life
Author: Stephen Covey

Discover the 90/10 Principle.

It will change your life (at least the way you react to situations).

What is this principle? 10% of life is made up of what happens to you. 90% of life is decided by how you react.

What does this mean? We really have no control over 10% of what happens to us.

We cannot stop the car from breaking down. The plane will be late arriving, which throws our whole schedule off. A driver may cut us off in traffic.

We have no control over this 10%. The other 90% is different. You determine the other 90%.

How? ……….By your reaction (the way you think and act).

You cannot control a red light, but you can control your reaction. Don't let people fool you; YOU can control how you react.

Let's use an example.

You are eating breakfast with your family. Your daughter knocks over a cup of coffee onto your business shirt. You have no control over what just happened.

What happens next will be determined by how you react.

You curse.

You harshly scold your daughter for knocking the cup over. She breaks down in tears. After scolding her, you turn to your spouse and criticize her for placing the cup too close to the edge of the table. A short verbal battle follows. You storm upstairs and change your shirt. Back downstairs, you find your daughter has been too busy crying to finish breakfast and get ready for school. She misses the bus.

Your spouse must leave immediately for work. You rush to the car and drive your daughter to school. Because you are late, you drive 40 miles an hour in a 30 mph speed limit.

After a 15-minute delay and throwing $60 traffic fine away, you arrive at school. Your daughter runs into the building without saying goodbye. After arriving at the office 20 minutes late, you find you forgot your briefcase. Your day has started terrible. As it continues, it seems to get worse and worse.

You look forward to coming home.

When you arrive home, you find small wedge in your relationship with your spouse and daughter.

Why? …. Because of how you reacted in the morning.

Why did you have a bad day?
A) Did the coffee cause it?
B) Did your daughter cause it?
C) Did the policeman cause it?
D) Did you cause it?

The answer is "D".

You had no control over what happened with the coffee. How you reacted in those 5 seconds is what caused your bad day.

Here is what could have and should have happened.

Coffee splashes over you. Your daughter is about to cry. You gently say, "Its ok honey, you just need to be more careful next time". Grabbing a towel you rush upstairs. After grabbing a new shirt and your briefcase, you come back down in time to look through the window and see your child getting on the bus. She turns and waves. You arrive 5 minutes early and cheerfully greet the staff. Your boss comments on how good the day you are having.

Notice the difference?
Two different scenarios both started the same. Both ended different.
Why?

Because of how you REACTED

You really do not have any control over 10% of what happens. The other 90% was determined by your reaction.

Here are some ways to apply the 90/10 principle. If someone says something negative about you, don't be a sponge. Let the attack roll off like water on glass. You don't have to let the negative comment affect you!

React properly and it will not ruin your day. A wrong reaction could result in losing a friend, being fired, getting stressed out etc.

How do you react if someone cuts you off in traffic? Do you lose your temper? Pound on the steering wheel? A friend of mine had the steering wheel fall off) Do you curse? Does your blood pressure skyrocket? Do you try and bump them?

WHO CARES if you arrive ten seconds later at work? Why let the cars ruin your drive?

Remember the 90/10 principle, and do not worry about it.

You are told you lost your job.

Why lose sleep and get irritated? It will work out. Use your worrying energy and time into finding another job.

The plane is late; it is going to mangle your schedule for the day. Why take outpour frustration on the flight attendant? She has no control over what is going on.

Use your time to study, get to know the other passenger. Why get stressed out? It will just make things worse.

Now you know the 90-10 principle. Apply it and you will be amazed at the results. You will lose nothing if you try it. The 90-10 principle is incredible. Very few know and apply this principle.

The result?

Millions of people are suffering from undeserved stress, trials, problems and heartache. We all must understand and apply the 90/10 principle.
It CAN change your life!!!
Enjoy….