Sunday, May 29, 2016

Simple Harmonic Motion

It's just a reaction, I don't really want this.
The hormones are acting up, that's all it is.

If I just ignore it, the chemicals will go away.
There is no meaning in this, yearn as I may.

It has happened before, nothing is new.
Time and again, I have begun to love you.

Others have stood in your place.
Yet you are the only familiar face.

Perchance something more it is.
This recurrent return, I think I really love you miss.

Thursday, May 19, 2016

Sultan Salim

Note: This is a work of mine from 2012. It was buried under a lot of zip files.
There are times when you are frustrated. There are times when you feel that you can do nothing but cry. And there are times when you feel invincible. Now was the time to feel proud. Already I experience the feeling of an old man looking back on his life and saying “I have done enough for a lifetime. I have done my part.” So much has happened in the past years that I do not know where to begin. It feels like I was barely a kid yesterday. The memories of pain move me to happiness. The memories of those painful moments fill me with ecstasy for those were the moments I overcame; not with help, not with sullen existence, but by fighting.
I am Sultan Salim.
Sultan of my own body. Ruler of the five senses. Commander of my will. Leader of my conscience.

I was born to my beloved but wretched parents Fatima and Farukh. Unlike most people I was born on the street. That was my first painful experience. I fell onto the road when I first came into this world. My mother’s arms did not welcome me, nor did the pent up leap of my father. My mother was dead and my father was sick. What greeted me was tar. Cold hard tar. I still carry the scars of that first painful experience which even I fail to remember. The rashes on my shin which remind my leg of how it was torn by the rough road. Like all other children of our creed I grew up ignorant of who I was. An all powerful being. I lived with my father, holding onto the memory of my dead mother. Nay, existed would be a better word. At the age of ten I got beaten up by a local bully over a garbage picking spot. At eleven I got beaten by a man over a sleeping spot. As I approached  twelve I was frequently beaten by my father for not getting home enough money. I cursed the miserly car drivers on the roads. At thirteen my father was shot by highway bandits and I ran from home. I put my head down and ran. Was it not in my hands how I lived? Was I not my own master? Why was I pushed about by fate?  
NO...
This shall stop now.
I am my own master.
It was at thirteen that I became the commander of my will. That very will which guided my destiny. The next day I went to pick garbage again. That bully had grown in strength and years. So had I. Over the same spot we had stood three years ago I asked him to apologize. I was beaten up again. I was my master. I refused to give in to fate. The first punch I landed was the last one. He gave in. Three years of being beaten made me tough. Three years of beating up made him soft. I asked him to join me, to work together and he joined me. I am glad at those years of pain. I made a good friend over that garbage heap. At twenty I fell in love. I shall never do that again. She was from our creed.
Lovely.........beautiful.
Eyes as dark and mystic as a moonless summer night. Hair flowing like black silver. A smile which made the Japanese sunset seem bleak. The sound of her voice made birdsong obsolete. Her words flowed from a well of honey and lingered in my ears longer than they should have. I loved her more than I loved my dead mother. And then she stole from me .... and left.
Why did I not see this? Why was I so blind? Why was it that I could not stop myself? Why could I not resist?
I was twenty and I became the ruler of my senses. A month later I walked up to her and asked her “Why?” “What is it that is really stole from you??” was not the reply I was looking for. No longer did her gait invoke love in me, no longer did her words drip of heavenly nectar. My senses were my own and I was their ruler. I asked her to join me and she gladly obliged. My heart tells me that I did good that day. Time has proven that decision wise. Rubina has been my wife for the past fifty years. We have lived together in harmony but never with love. Passion ; yes, but never love. For what did my senses lead me to be disillusioned by her enchanting ways? Was it the satisfaction? It was not, it was the greed to see what was not. I am thankful for that pain.
I was twenty five when I met Govind. It was a short meeting. I had run him over with my car. The little street beggar was running to sell an image of Vishnu. It was ironic how that very Vishnu had let him be killed. It could have been me running about the street years ago. The brother of Govind was Vishnu. Their parents dead and buried ;they were veterans in this world by now. One veteran was dead already. At twenty five I became the leader of my conscience. The confluence of guilt and fear lead to one direction only. I adopted Vishnu. A year later a baby girl was born to Rubina and I rejoiced as she stepped into my arms. My children would be greater than all of mankind. I had great dreams for them. They would be better than their parents. I honour the pain Govind caused me. I got a great son in Vishnu and an exemplary daughter in Sahiba. The Sahiba who grew up and flew away.
Twenty years I lived as Sultan of my own body. I tremble even now to tell Vishnu the truth of my actions.
I am Sultan Salim.
And I must sleep now as it does not benefit my age to stay up late.
.
.
.
Vishnu’s face hovered above me. Rubina held my hand. After all these years I had come to respect her. It was deeper than love.....for I had come to know her true nature. We had sailed together and that bonded us like rock to earth and cloud to sky.
Rubina......
She held my hand and I was comfortable at her touch.
Vishnu......
He spoke to me lovingly. His eyes doting on the only father figure he ever had.
Sahiba......
I did not see her now...my little angel has flown away....


They were worried. I did not know why.
They spoke but I did not hear. They smiled but I could see the fear and sadness in their eyes.
Life has taught me something after all. Even after all these years it is difficult to contain the waters of emotions held in our bodily vessels when the urn itself is rocked by the winds of fate and tides of time.
Ah....
It is finally that time. The time when I shall be reborn as someone else. To repeat these actions of mine. Reborn to learn again what life has to teach us. I drew my breath. I was not done yet. Vishnu had to know. The words raced up my chest but fell short of reaching the air. In a whisper fainter than the spring breeze itself I call out to my son. The son whom I had nourished to carry on my legacy. With concern born out of years of love he lowered his ears to my lips. I drew my breath in a final effort. The sultan inside me roared at my helplessness. My senses were failing me. I looked at Rubina.
“Tell Him”
She understood. Eyes as dark and mystic as a moonless summer night blinked away tears which shone like morning dew. Hair flowing like threads of moonlight. A smile which expressed sad knowledge. The sound of her voice like pearls falling off her lips. Lips that were like old roses. Flowers which have lived their life and aged with time. I loved her more than ever.
Before my eyes she told Vishnu of my deed. I saw him drop onto my bed. He looked at me.
A lonely tear cascaded down his cheek.He knew I could no longer hear him and yet he said.
“I forgive you”
Vishnu. The ever forgiving protector of his devotees. Magnamus in his deeds and enormous at heart. The source of all knowledge. He who sees all. I loved him more than ever.
My work here is done. Come, O friend of life. Come and take me to your abode.

Come to me; my death.

Thus I take leave from this world. A street boy who became Sultan. Who raised prince Vishnu and Princess Sahiba. Who endured along with his begum Rubina. As I step into another world I remember my parents. Fatima and Farukh. Who shall introduce me to the next world?  Let the all mighty power bless them. They gave birth to a legend. For eons my name shall echo in the city streets. Not because of what I conquered. But because of who I conquered.
I am Sultan Salim.
Sultan of my own body.
Ruler of the five senses.
Commander of my will.
Leader of my conscience.
The learned one.

Saturday, May 14, 2016

A Regular Expression Engine in Python


Regular expressions are quiet useful in programming tasks. They are a useful method to search for patterns in long strings of text. For example the pattern "(c|b)at" allows us to search for either 'cat' or 'bat' in any string that this pattern is run over. This example was a simple one and regular expressions in practice are far more powerful and complex.

One must take care however in remembering that regular expressions are a loaded mathematical term. They are not the same as regex and regexp since those two do not make regular languages.

Here, for the sake of brevity we shall call regular expressions regex. Regexes are usually made using Deterministic Finite Automatons. They take a string of input symbols and tell us if the DFA accepted the symbol string or not. Such an activity is called the run of the DFA.

Steps
  1. We define that our regex engine will only provide the basic elements of concatenation, union and kleen star. Thus '|*' are the only special characters allowed besides the other things in the alphabet. 
  2. We first build a Non-Deterministic Finite Automaton with epsilon transitions using Thompson's construction algorithm from the given pattern.
  3. Then we convert this e-NFA to a regular NFA without epsilon transitions by the epsilon closure method.
  4. The new NFA is converted to an equivalent DFA by the power set construction method.
  5. The DFA is finally run on a string. The Union (|) and the Kleen closure (*). Concatenation is assumed for consecutive symbols.
  6. Upon completing the run, the DFA either returns True or False depicting that it has accepted the string or rejected it.
Example

For the regex '0|10*' (which means either a zero or one followed by any number of zeros) on the alphabet '01' the following strings return results as shown:
  • '1' : True
  • '0' : True
  • '01': False
  • '10': True
  • '11': False 
The entire code is available as a gist.