Saturday, June 27, 2020

Descartes and C Programming

"Whatever I have up till now accepted as most true and assured I have gotten either from the sense or through the senses. But from time to time I have found that the senses deceive, and it is prudent never to trust completely those who have deceived us even once." - René Descartes


I have always been moved by the nature of thought that produced the ideas of Descartes and the Cartesian coordinate. Also, I am writing C codes for the last thirteen years. I would say that I find it to be the closest of the idea of the Cartesian coordinate.

I have not yet went through one standards of the C language fully. I have found C to be intuitive and I thought know how things can be achieved with it. I have been proven wrong earlier as well. Very recently, I wrote a code similar to this and it crashed with newer GCC.

It turns out, that if I perform pointer arithmetic, I tell the compiler that it is a valid pointer and it is guaranteed to be not equal to NULL and such checks can be optimised out (or "in")!

I tried with GCC-8.3.0 and 9.3.0 with "-O3" option and the latter crashes because the while always evaluates to true.

Please refrain from suggesting "better" ways to do something. This post is contains a snippet and not the whole code and the post is about standard behaviour and not how to write better C code ;)

Just like life, it is wise to be not too trusting with C.

Tuesday, December 24, 2019

About Vacations

I have worked in various companies in India (two cities) after college for about seven years. Either of the cities are not my hometown or in my state and have vastly different cultures and food habits. Somehow foolishly I have not considered them my "home" when I lived there and would fly to my hometown about three/four times a year and think that I am "home". These would exhaust most of my vacation time. I cannot say for most, but many do this.

I recently started working at a University in a country which is known for its work-life balance (at least on paper). And, I started to realise that I was not quite thinking right about my vacations.

I noticed a colleague who took a month long vacation. Being a naive person I assumed that guy must have gone to some place he feels "home", or to a nice vacation place, I asked him what did he do for vacation, and he told me he was in cottage with his friend and no cellphone connection and he just was there.

It sounded strange to me. But, then I just realised, I never had a true vacation. Because, I always went to my home city or a trip to somewhere for my longer vacation. And, I would become busy with visiting relatives, making up for lost times in long distance relationships, making and sticking to the itineraries if I was visiting places, and other necessary works and no time to relax, which was supposed to be the essence of "vacation". And, I would return to my workplace feeling worse than when I left because this is not my "home" in my mind.

These thoughts made me think if it is necessary to call the place where you live, home, to actually be on a vacation and relax. I felt that some things in life, like the feeling of "home" or relationships, should be a part of your daily lives rather than needing you to always put too much effort into and take from your vacation time just to get that feeling.

What I also realised, that the very nature of work-culture situation at most of the workplaces in India numbs you from a few feelings which you can only feel if you take time to think about. But, maybe again, all these are just about my personal idea of vacation which is different for everybody.

Sunday, September 02, 2018

Monty Hall Problem

Today I want to talk about a game show that used to come to Star Plus, "Khullja Sim Sim". If I remember correctly, Aman Verma was the host. I just used to watch without understanding much.

During college, I read about the Monty Hall problem and it was so counter-intuitive, I could not believe it and thought of it as just a theoretical analysis and the real life situation would still be same for both the situation. Later, I forgot about it.

Very recently, I again read about it and I remembered that I was sceptical about it the last time. But, now I could write code.

So, I wrote a code which randomly puts prize in one of the three doors. Then, the player has a random first guess. The game then opens an empty gate and the player is given a chance to change his earlier choice. I tracked number of wins separately for both the situations when the player changes their first choice and when they do not.

Surprisingly (for me, not for those who understood the analysis properly), the result is better when the player chose to change their first choices. Double, to be precise.

The analysis loosely translates to the fact that, if you do not change your choice, your probability still remains 1/3 whereas, if you select, it becomes 1/2 since the second time, only two options left.

I understood the argument properly even the first time. But, did not realise how deeply the concept of probability is entangled with our day-to-day situations. It was overwhelming for me and I wanted to share this with all of you.

You can find the code here. Do let me know what do you think about the problem.

Wednesday, June 27, 2018

Something About Professional Growth

I have done job search very recently and a few years back to extend the career horizons. This post is not to provide tips, but to share one realisation that I have gone through during the process.

What happened a lot of times with me is that, it seemed to me that I would be a perfect fit for a role. My interview would go well and I would be certain that the people at the other end of discussion loved me. But, then I would get a regret mail. Whereas, I would get green signal response for roles which would not match my exact past experience. I used to be flabbergasted.

But not anymore. What I realised is that when a potential employer look at your past experience, they are trying to assess you based your past achievements and determine how you take challenging situations. Most of the time they are not looking for exact matches. Of course, for very specific roles, this is not true. But, this holds good for most of the situations.

What they want most of the time is that you have a room to grow. If you are an exact fit, you would become bored quite soon, well unless you have home loans.

I believe this is a good thing. Variety and diversity always help. Maintaining diversity in anything is helpful when things start going south, and you would not realise about problematic nature of mono-culture when things are good. I personally believe even a very technical role needs certain room to grow.

Something to think about when you do not hear positively from a potential employer for a role that exactly matches your past experiences.

Saturday, June 23, 2018

Preliminary Monte-Carlo to Find Value of Pi

This may be called Monte Carlo, but, I do not think it is a good example. Nevertheless, let us try to see. This is a product of a situation when you do not have much left to watch on Netflix.

The idea is to use the pseudo random number generator in C to get random points inside a square of sides with length 2 units. We shall try to determine if a point is lying inside the circle that is inscribed inside it. If random numbers are well spread, then ratio of number of points inside the circle to the number of points inside the square should be equal to that their respective areas.

Apart from the usual stuffs, one thing to note is that the pseudo random number generator in C is not thread-safe. The seed gets locked and its state gets changed in usual rand() call. GCC kindly provides this thread-safe version of it (rand_r()). Otherwise, with multi-threading, run-time actually increases.

Another minor thing is that since the pseudo-random numbers generation is mostly similar time consuming, default OpenMP for option (static) is best fit.

This is a plot of percentage error vs number of iteration. Probably due to pseudo part of the random numbers, we might not ever reach very close to the real value as we increase number of iteration most of the time.

You can find the code here. Please let me know your comments.

Wednesday, May 04, 2016

About fever, life and thermodynamics

  I recently had a very bad fever. One which lasted for about two weeks. The thing that do not like about fever the most is that it happens in one day but goes away gradually. So, you start feeling bad from feeling good in less than a day. But, you do not get well suddenly! You do not get the feeling of being well too quickly. That is what I do not like about fevers.


  Thinking about it, what I realise is that this is of course true in every aspect of life. If we let everything to be on their own device, things will become more and more chaotic and it takes quite some effort to make things orderly. That too, will happen gradually.


  We had a chemistry teacher in our school, who tried teaching us about thermodynamics, entropy and chaos. Well, he mostly wasted his and our times. But, he said something that is still in my head. He said that, life is thermodynamically unfavourable process. So, it takes effort to keep life going. I think it is true for all the aspects of life in general. It needs just one infection to get you a fever, one small disagreement to break off a relationship, one small mistake to let go of an opportunity of a lifetime.


  There is one quote often attributed to famous Indian statistician P. C. Mahalanobis. I am not sure about its authenticity, but it says, disease is contagious, health is not. It takes very little effort to go towards disorderliness, but a lot to keep it as you want something to be.

Saturday, January 19, 2013

Identify, Recognise, Remember and Value

  We all remember the candy that was refused by our moms. I used to be very angry and annoyed with these instants. I used to wonder why exactly she was refusing to let me have a candy. As a kid, I wondered if she was having candies behind me and not letting me have some of them.

  After I grew up a bit, I understood I only remembered the times she refused and not the times when she allowed me to have some candies. I understood that she was doing this for my own god. She was stopping me from having candies more than certain limit as having many of them might not be good. I also understood that she did bar me from many activities beyond a certain limit as it might have had the some bad effect on me.

  Then my age increased some more. I found that some people in my life is actually barring me from doing certain things. For those who don't personally know me, I am a bit slow in noticing and understanding everything. I thought they were being selfish and trying to not let me have fun in my life. And many times, not always, I went on doing those things they asked me not to do.

  Most often what happened is that I somehow either felt bad, got hurt, or had materialistic loss; not always of course. I thought about it. I understood that there are few people in my life who want the very best for me. As they are not me, they can observe and understand my life objectively which is very hard for me to do as my life is my own. Of course, they understood me only that much, till the point I allowed them.

  I believe all of us have that set of few people in their lives those who want the very best for them. We need to identify and remember them. We need to understand their words from a futuristic point of view keeping in mind they want only good for you. We need not always refuse the ideas which may cause not to have immediate material/emotional displeasure. We need to value these people's opinion. And in a world like this, which is mostly selfish, we need to value these people too.

Thursday, August 30, 2012

Crossroad In The Way Of Understanding People


In life you come across many crossroads. They are of many categories. They will make you think and decide about the issues. But what if the crossroads are coming in the process of the decision making itself.

I always try to find answers, rather explanations, to everything that is happening around me. It always irritates me not to have the explanations. Sometimes I even pay a very big price to obtain knowledge about something that is concerning me and consider as my gain even though in general notion it does not seem so.

So, it is of no wonder that I always try to get the explanations of any given situation or anything that is happening to me.

No matter how hard you try, you end up expecting in every sphere of life. As of now, without practice of meditation or something similar, one is bound to have lost control of your desires. So in our lifestyles, expectations are mostly inevitable. But what are the consequences?

You expect something. That means there is usually 50% of chance that you will not get that. Also, expectations are supposed to be fulfilled by a person  who is NOT you.

What if you expect something, and then it does not happen. Then a situation comes where you cannot have that something and now the people, whom you thought would fulfil your expectation when there was a chance, starts saying how they want to fulfil them and cannot do now only because the current situation does not give them any chance. When just maybe two days ago situation was such and they just ignored it.

It also may happen that there might be a chance that such situation might come again. First they make sure that the situation does not happen. Then they will say had it been that way, they could have done this and that.

All I want to say that I am now growing up. Although it is very late, but I am happy that I know tomorrow when I shall be going to bed, I will be more mature than today. I learnt many things about life in very harsh ways as I was late. So I am going to believe whatever I understand instead of what I am told. Because only your thinking process and views will remain with you till the end. Anyway, people believe whatever they want to believe. This also is my observation. So as a part of growing up, I shall also go by this rule.

But on the same note I know this also, that I will not stop believing in people. That is the last thing one should do. But what you will believe about them is choice that left to you by the Matrix.. :P
I will take the crossroads that suits me. I guess that is what everybody does.

Sunday, July 08, 2012

Be Careful What You Wish For

I am a very big fan of Dr. House. He sometimes says "you can't always get what you want." I too believed that, until very recently. As you cannot get what you want immediately, this might seem true for some time. Some of my experiences made me think in other ways.


I saw this documentary "Law of Attraction" (not the movie) almost three years ago. It says right attitude of having something already accomplished which is not accomplished yet, will actually help you to reach that destination. Of course it sounds absurd at first. But I believed that positive attitude is much better than a negative one.


Also in a conversation around two and a half years back, a good friend asked me if at the back of my mind I was still interested in physics or not. I was not doing well with my studies. It made me think that whatever idea you dump on the back of your mind, you consciously may forget it. But it stays there and has effects on all your future actions. They can as well be analysed and understood nicely from that point of view.


Observations show that apparently strong dams built on rivers are required regular maintenance, even though the calculated shock that can absorbed without any damage is more than the actual force the river exerts for a given amount of time. Similarly, it may be inferred shows that if you continuously let something stay at the back of your head, it affects your action in achieving or fulfilling those ideas.


That is why I realised that whatever you want, make sure you want it in the long run. Because if it is not, you might not actually like it when you get it. But nothing can be done then as everybody would know what you were up to all these times and all the situations created were already very strong to not let go off the thing you wanted all these years due to your actions. So, I think it would be wise to take time to decide wisely what you really want instead of not liking it much later. Be careful what you wish for, it might come true.

Sunday, July 01, 2012

Human Nature: As I Found It


As I am trying to live my life rather than merely existing as mentioned in many great people's quotes, I keep coming across many astonishing revelations about human nature. Since our interactions and involvements are mostly with other humans, this continues to intrigue me.


I had a habit of reading classic novels and short stories and also old English poems (mostly of romantic age). My father being a English literature student, I had relatively easier access to these classics. I read many such works at, one can say, an unprepared age. Some of them, if I am lucky enough to find a correlation with something in real life struck me very hard. Some of them did not.


I somehow always restrained myself from learning about human nature through human interactions as most of the time I used to find this action inseparable from judging people by their actions. Well, until very recently. I realised that probably it is necessary for living comfortably, for not getting hurt again and again.


So, now that I have decided to start learning from first hand human interactions, I started realising that almost all words in them have a significance. So, I may realise something new today, but when I think about it, it is very much normal to the world already.


One of the lessons that recently I learnt about human nature is that people will do whatever they feel important anyway and find and excuse to not do whatever they feel is not important. This is true every time. No matter what your relation is with that person, be it your parents, best friend, teacher, that special someone or even your admirer. It does not matter what prejudice you have about them or what you may would like them to do. And no matter how much important you think something is, if another human does not think it is, my experience says, better expect them to do the opposite. Less disappointment for you.


But in the end, it's all good I think. Life, after all is just a ride. People with different point of view will keep coming and neither you it's worth the effort to avoid them, and not you should. I think enjoying the ride is all that matters.