Thursday, July 30, 2009

A programming language in my name!

While googling in a sleepless night, I found something intersting (interesting for me and all other Toms!). A good looking programming language named "Tom" which is my name. I just went through the official website and found it was cool. I liked some of its specialities available, and also it's license.-Yes, it's under GPL (GNU General Public License). Some of the pecularities are: (I just copied it from the official site)
  • TOM sports extensibility of objects: a class is not just defined by its main definition: classes can be adjusted, even at run time. A prime example of this is to modify in your program a class offered by a shared library, just to make it suit your program better.
  • TOM methods employ default argument values and multi-valued returns;
  • TOM has multiple inheritance - with semantics much simpler than in C++ or Eiffel and obviating the need for interfaces (Java) or protocols (Objective-C);
  • TOM offers reflectivity on objects, their classes, member variables, and methods;
  • TOM discerns classes and a few basic types - like Java and Objective-C;
  • TOM has conditions modeled after CLOS conditions;
  • TOM, as compiled by Tesla, the first TOM compiler written in TOM, adds blocks to the language;
  • The TOM standard libraries offers time-constrained garbage collection, multi-threading, distributed objects.
In their FAQ, I found a question "What does the name "Tom" mean?
The answer given was like this: "The name TOM is a name. Names don't need to have a meaning. :)"
Well, here is simple "Hello Tom" program in TOM which resembles C and Java.

int
main Array arguments
{
[[[stdio out] print "hello, Tom!"] nl];
}


Currently Tom is available for Linux,BSD platforms. An unsupported version of win32 platform also
Visit official TOM website

Monday, July 27, 2009

What's the value of 0/0 ?


Do you know what's the value of 0/0 ?
Most books just don't care about it. Also many teachers are not interested to touch anything like this. Students are fearing to see this, especially while they are doing some calculations on the exam paper!
Anyway, it is good to be aware of 0/0. I continue this article assuming you know basic addition, multiplication etc.
One question: What's the value of 10/2 ?
It's 10/2 = 5. Is it?
We got the answer as 5. Is that mean 5*2 =10 ?. For example, if you have money Rs.10 and distributed to your two friends equally. Then your friends get 10/2 = Rs.5 each.
From the above example, we can generalize that if a fraction exist in the form x/y=z , then z*y =x.
please note the above line. I will tell you more about that line!
Then the question is if you divide your Rs.x to y people equally, each will get  Rs.z. Then what is z?
The answer z is a number which satisfies z*y=x. In the above example, you put different values for z such that, z*2 =10. Then z is the amount in your each friend's hand. Here 5, the only 5 satisfies the equation when it put to z. Thus each of your friend get exactly Rs.5.
Then consider the case of 0/0 . Like the previous example, if 0 is divided to 0 people, how many rupees each of your friend get? If  the answer of this question is z, we can write z*0 = 0. Put some values for z in order to satisfy the equation. All values of z which satisfies the above equation are the solution. We know that multiplication of any value with 0 is 0. So z can take any values to satisfy the equation.
If the solution of z is written in a page, your page may not be sufficient to include all solutions of the equation because solution is 'any value'. More mathematically,
z = -infinity.......................0.......................+infinity
So, 0/0 = any value
It seems very interesting on the first sight. You have nothing, and you are dividing that to nobody. Then the amount in the nobody's hands may be millions, trillions or anything. If you think, this is like a magic to generate millions from nothing, you are absolutely wrong. Think about it.
Let's go for an example to describe what's actually I am trying express. To understand this example, you should aware of a great law named Ohm's law in Electricity (The circuit shown below is stolen from Wikipedia). If you don't know anything about Ohm's low, you must make yourself aware of that before going to continue.
According to Ohms law (refer picture), R is V/I.
R=V/I
If V=10V and I=2A, then R = 10/2 = 5 ohm. In the above picture, if Voltage V=0, Current I will also be zero (without voltage there will no current). Then R = V/I =0/0.
According to our previous result 0/0 can be 'any value'. So R = 0/0 simply means R can take any value. R can be anything.
R*0 =0 can be treated like this: R is the values that exists when V=0 and I=0.
If you put a resistor in your pocket, the applied voltage V = 0 and hence current I = 0. So you can put Resistances of any value in your pocket. Think about the world of 0/0 = a fixed value. For example, take the fixed value 0/0 = 100. Then Resistance R =100ohm is the only value that can put into your pocket and others can't!
Seems funny? but it is fact.

Sunday, July 26, 2009

Parallel port programming using python

Setup parallel port in linux (Debian/Ubuntu)
You should have installed python on your distro. You must have the previlages of 'su' to do the following installation

# apt-get install python-parallel
# rmmod lp
# modprobe ppdev
# python

>>> import parallel
>>> p = parallel.Parallel()
>>> p.setData(0xFF)


Assuming you have some basic python knowledge. If you didn't install pyhton -parallel, you can't import parallel. Now p.setData(oxFF) sets every outputs of parallel port to ON. Try different values instead of 0xFF. (To do this you require basic knowledge of hexadecimal representation of binary numbers). Try this chaser program.

x=[1,2,4,8,16,32,64,128]
while(1):
for i in x:
p.setData(0xFF)
time.sleep(2) #Good night for 2 seconds


The program will work until you force to quite python or an unexpected UPS failure. That may be funny ;-) But Intentionally did that for the program simplicity.

No Linux? Windows only? :-( Just try it out

There is nothing to do in windows. Download latest python first. Install it. Then download pyparallel for windows fron sourceforge. Install it Now everything OK. Open python either by command or open IDLE (It will be installed with python core in windows). Then type the following:

>>> import parallel
>>> p = parallel.Parallel()
>>> p.setData(0xFF)


The example chaser program is also applicable for windows platform.

Read my post on parallel port programming in C/C++

Wednesday, July 22, 2009

Teach your computer how to speak!

It is good idea to teach computer to speak!. There a number of programs available for winXP paltform, but here is a unique program "espeak" for your linux. Just enter the command in terminal,

$espeak "Boss, I can speak now"

will work fine. It is useful for some scripts in linux to remind some status of computer to the user like a personal assistant. espeak is not an internal bash command and need to be installed. I simply installed in my Debian from repository.

#apt-get install espeak


The command above will work well with ubuntu systems also. If you are using any other distro, you need to download and install it manually. Click here to know more.

Here is a simple python program which uses espeak as system command. To use it you require python and espeak installed.

#! /usr/bin/python
# File: speak.py

import os
from Tkinter import *

class App:

def __init__(self, master):

frame = Frame(master)
frame.pack()
self.button = Button(frame, text="Click", command=self.activate)
self.button.pack(side=LEFT)


def activate(self):
os.system('espeak "Boss, I can speak now"')
print "Boss, I can speak now"

root = Tk()

app = App(root)

root.mainloop()

Just copy the above program into a new file named speak.py and 'cd' into the directory and enter,

python speak.py


You are free to use this program anywhere since espeak is under GPL.

Friday, July 17, 2009

About our knowledge

We dig everything from the centre. Every experimentation of any branch of science starts learning our world neither from the beginning nor from the ending,but from in between. We don't know the beginning and the ending. But we dig to above and below from the middle, but never reaching anywhere.
For example, a man start to learn about the world. He first learn about the present things -trees, birds, humans etc. He digs to the past and also digs to the future. Here time is the base. When size becomes the base, that man start to learn back to molecules, atoms, sub atomic particles, quarks....And when going up, sun, Milkyway...Here again we don't know the ending. It seems that, man's knowledge is isolated in every axis didn't touch the starting or ending yet. Yes, it's really floating!

Thursday, July 9, 2009

Physical Interpretation of DeMorgan's law

I am asking you what is De Morgan's law. This may be the answer.
If A and B are two events,

(A+B)' = A' . B' and (A.B)' = A' + B'

(Here the operator ' represents the compliment of the operand. That is If A is 'yes' then A' is 'no' and if A is 1 then A' is 0 and vice versa). I assume you have basic knowledge of Boolean algebra. Now I am giving a physical interpretation of the law which is very useful in analising the law.

Consider first law,

(A+B)' = A' . B'

Here '+' is OR operator. That is A or B. Let Y be an event of shutting down your computer. You can do it in two ways and B.

A=>shutdown manually by pressing the power button of CPU.
B=>click 'shtdown' using your mouse.

Then,
Y=A + B ie, Y= A OR B

Another iterpretation is that, you can turn off your computer by either clicking 'sht down' or by pressing power button. If any one event occured, the computer turns off. ie, Y become true.

One day, your friend came to your home and want to learn about computer. He did something in your computer in order to turn off.Unfortunately, the computer didn't turn off. He reported you in the other room. Then you think in this way, what may be the reason why the computer didn't shut down. The output occured is Y'. ie, computer didn't turned off.

Then from the previous equation,

Y' = (A+B)'
Applying De Morgan's law,
Y' = A' . B'

Here the interpretation is that, The event A is false and event B is false. ie, he neither clicked 'shutdown' nor pressed power button.

Take De Morgan's second law (A . B)' = A' + B'
Consider two dependent events. For example,
let A and B be two dependent events. If your friend dont know how to call someone using a coinbox telephone. The procedure written on the side of the machine is first put the coin and then dial the number. They are dependent events.
A => Put the coin.
B => Dial the number.

Here the output Y is to call somone successfully. ie Y = A.B
(Here A.B is not equal to B.A which is another boolean theorm. Here just don't think about it.It will be explained later)
Unfortunately, your friend could not call the other. He asked for help. Then you analise the problem why he didn't call.

Y' = (A . B)'
By, De Morgan's law,
Y' = A' + B'

ie, he either didn't put the coin or dial the number properly. The above example is conditional events.