Sunday, August 3, 2008

Mobile T9 Dictionary Implementation in BASH

Well, a computer is good if it does the job.
So, without taking into account trie structures or complicated search algorithms, here's my T9 implementation in BASH

#!/bin/bash
# This bash script does something outrageous.
# It attempts to reproduce the T9 capability
# of the Mobile Phones !

umask 077
DICTN=/tmp/dict.$$
NUMN=/tmp/numn.$$
trap "exit 1" HUP INT PIPE QUIT TERM
trap "rm -f $DICTN $NUMN" EXIT

tr A-Z a-z /usr/share/dict/words |
tr a-z 22233344455566677778889999 |
tr -cd a-z | awk '{print NR ":" $0}'> $NUMN

awk '{print NR ":" $0}' /usr/share/dict/words > $DICTN

if [ $# -eq 0 ] ; then
echo "Usage : t9.sh "
exit 1;

else
PAT="^$1"
join -t: $NUMN $DICTN | cut -d":" -f 2,3 |
grep "$PAT"| cut -d":" -f2 | sort
fi


It surely does the job !
Any comments ?

Friday, November 2, 2007

Reflections...

Its a nice way to view the world around you in a rather amusing scientific way. After all we have only one world! Laets make the living here fun and really happy !!

Have you ever looked at a mirror? How does a mirror work? Surely, you might begin to say of reflection and all sorts of things. But how does then reflection work? There should be a law governing the reflection. No, not Snell's law. It just gives the relation between angles involved in reflection and incidence.

Now, this is exactly how reflection works. Suppose an Electromagnetic wave hits the surface of a silver coated mirror. Now, from the previous post, you will have an idea of how electromagnetic waves propogate. Ofcourse they propogate in the direction of E x H. Now, suppose this is being incident on our silver coated piece.

The principle behind electromagnetic shielding is the fact that electromagnetic waves disappear inside a conductor. How does this happen? Well, in a conductor, the fields vanish. So there is no E X H for the EM wave to propagate. But, by the theory of Energy Conservation, this energy is somehow to be maintained. What does it do ?

The incident wave reflects! Thus, better the conduction of the medium of the mirror, better the reflection and hence higher the quality of the mirror. There a lot of other factors affecting reflection including smoothness, thickness etc.

Sunday, October 28, 2007

Conduction : Behind the Scenes

Well, all you (!) hopefully have switched on or off an electric appliance in their life . What happens when you do that? No, don't tell me that it brings electricity to an electric appliance. I know it does, but what actually happens?

The answer lies in this paper, published by the renowned Scottish Physicist, James Clark Maxwell in 1861. The laws that he formulated from various laws existing at that time connecting electric fields and magnetic fields became the basis for what is known as Electromagnetism. He was the one who unified the previously separate forces of Electricity and Magnetism. His equations, actually extension of Gauss Law, Ampere's Law and Faraday's law gave all that was to be known of an electromagnetic transmission.

Maxwell's equations theoretically predicted the existence of electromagnetic fields and electromagnetic propagation. But it was only years later that Henrich Rudolf Hertz succeeded in generating and detecting Electromagnetic waves.

Now, Electromagnetic wave has some interesting properties. Consider a wave travelling along a perfect conductor. The propagation constant of such a wave has a real part, often denoted by α, which is a measure of its attenuation. For a perfect conductor, α has a value which highly dampens the EM wave, once its frequency gets high. Now the inverse of α, ie (1/α) denotes the quantity called skin depth. Skin depth is a measure of distance that the wave can travel inside a conductor before it gets attenuated to a considerable extent. Thus we see that propogation of an Electromagnetic wave takes place only on a thin outer layer, commonly and literally referred to as the skin. This effect is called the skin effect and its applications are multifarious.

Now, what happens when you switch on that devicce? The current flows due to a potential difference between the source and load in the form of an electric field. As soon as the switch is on, an electric field is established throughout the wire, starting from one end. The direction of the field is radially outward, resulting in a magnetic field around the conductor. The direction of the magnetic field is anticlockwise(when looking from source end). Hence a disturbance quantified by the Poynting vector, E x H begins to propogate along the direction of E x H. ie in the forward direction, when looking from the source end. This disturbance establishes the electric field everywhere. Thus the electrons present in this field experiences a force which makes them move and hence conduct. Thus we see that conduction actually takes place at the speed of light !

So, the next time you switch on, remember, you are generating Electromagnetic waves around !!!

Friday, August 31, 2007

Undocumented Instructions, Why?

If you haven't heard of undocumented instructions, here's a quick primer.

They are opcodes that used to be present in early microprocessors due to side effects of different wiring circuits in them. They were usually left undocumented or rather cleanly left out from the official documentation and hence the name. But such policies were not to deter the exquisite brains of the geeks and they found out ways to exploit them. These instructions were not guaranteed hundred percent success. Usually, they amounted to a system crash, but in some rare cases, they produced something of value.

Early game developers of systems like Amiga, Commodore 64 etc used such instructions to speed up certain time critical process and hence optimized the system.
Certain instructions

Such instructions usually provided the programmer shorter ways to attain results. These instructions were actually curses to the chip designers. With each revision, such instructions were bound to change and resulted in crashing a perfectly working program.

Designers later began to trap such instructions in design phase itself and as a result, the volume of such instructions have sunk to a minimum. Certain instructions like SALC (set the AL register depending on the Carry Flag, opcode D6), AAM immd8 (Divide AL by immd8, put quotient in AH, Remainder in AL, opcode : D4) from the x86 family were later documented.

Thursday, August 30, 2007

Fuzzy Logic



Fuzzy logic is giving new dimensions to everything around us. Lets first focus on what fuzzy logic is. As humans, we think and operate. Our process of thinking can be said to be a form of fuzzy logic. I.e., all process and applications that are not linear and can’t be treated as non linear can be said to contain no clear cut logic. The logic involved is fuzzy in nature.

What does that have to do with designs? Well, the world and its applications are changing. Electronics have been applied to even very obscure applications. Certain applications lack a clear cut logic or mathematical model to be correctly implemented. Such applications which have been dubbed to be beyond the scope of normal electronics are now possible through application of fuzzy logic to solve the problems.

Put simply, fuzzy logic revolves around the basic principle that “X and Y equals Z”. How much X and how much Y is application specific and can be found out either through trial and error or through normal use of the application. It may seem like the concepts of self learning programs. IT may a bit, because in today’s world, its hard to distinguish one from another. Neural Programs and fuzzy logic have been tightly integrated today, so that it is impossible, virtually to separate them.

A number of factors or variables are considered in generating fuzzy logic. The idea behind a fuzzy engine is the definition of proper variables and the rules governing them which effect other process. One of the most important variable, for example may be an error function which calculates the difference between the actually obtained value and the required value. A rule is to be set so as to reduce error function within a specified percentage of actual value. The differential of error function can provide the rate at which the system responds, thereby providing a measure of the stability or responsively of the system.

What you just read was a primer on fuzzy logic. If you find the topic interesting, feel free to mail me or comment here on this blog to which I can promptly respond and of course you can go after the countless books that talk about fuzziness and fuzzy logic.

That brings an interesting question. Any ideas to generate a fuzzy cryptographic scheme?

Comment !!

Wednesday, August 29, 2007

Enabling Linux style file control in XP

No doubt many of you have dreamt of the user level file control present in Linux/POSIX type systems. Make no mistakes, XP has got the same feature too. But perhaps, its a little underpublished.

Here's how :

1. Open an explorer window.
2. Click on View
3. Click on Folder Options
4. Click on the view tab.
5. Scroll down below and uncheck "Use Simple File Sharing(Recommended)".

and voila, you got a per user controllable XP. To add permissions on whom to use and all, right click the concerned file and click on security.
Here, you can control permissions, set and deny access and permissions.

Nice, ain't it?

More info is available at Microsoft Page here

And finally, a note of warning. It is found that this feature is best available on a drive running NTFS.