Math sure is fun

With years of looking into the math and learning the same 10 digits in various combinations possible, its comes to a point that , what we know is the only solution and if it does not fall into what we know as the concepts its not supposed to be a possible. Here are few solution that makes one enjoy the possibility of math and the fun in it.. Starts with the basics of math and ends with a solution thats not supposed to make sense.

1.

Proof for 1 = 0 or actually 2 = 0.

Lets take two variables a and b with values = 1.

a = 1
b = 1

a = b
a2 = b2
a2 – b2 = 0
(a-b)(a+b) = 0
(a-b)(a+b)/(a-b) = 0/(a-b)
1(a+b) = 0
(a+b) = 0
1 + 1 = 0
2 = 0

2.

Now to prove 2 = 1.

-2 = -2
4 – 6 = 1 – 3
4 – 6 + 9/4 = 1 – 3 + 9/4
(2 – 3/2)2 = (1 – 3/2)2
2 – 3/2 = 1 – 3/2
2 = 1

Two solutions which contradict the basics of math we have learnt till date. and also they contradict each other. With some googling found out that the first solution has a flaw when we try to divide the number by zero(a-b)  which is not allowed. The second solution , taking square roots always provides with a pair of values , + and – . since we are taking only the positive values the result is confusing.

Funny and Creative Programmers comments

Programming is always a stressed work. But it still is fun and creative. Here are some of the programmers comments collected during stumbling. Starting with my favourite :D

//

// Dear maintainer:

//

// Once you are done trying to ‘optimize’ this routine,

// and have realized what a terrible mistake that was,

// please increment the following counter as a warning

// to the next guy:

//

// total_hours_wasted_here = 16

//

=======

#define TRUE FALSE

//Happy debugging suckers

========

//You are not expected to understand the following

and

//If you can’t do pointer math in your sleep, while

//driving a car backwards on the freeway,

//you shouldn’t change this routine.

and

//Yes, this is stupid. no it wasn’t planned. Drunken

//Lemurs change the spec every day. Check your mail.

//US Postal mail, not email. They’re not that advanced.

========

//Don’t touch it or ninja will punish you

========

//Dear future me. Please forgive me.

//I can’t even begin to express how sorry I am.

========

// I don’t know why I need this, but it stops the people being upside-down

x = -x;

========

return 1; // returns 1

========

Exception up = new Exception(“Something is really wrong.”);

throw up; //ha ha

=======

//When I wrote this, only God and I understood what I was doing

//Now, God only knows

=======

// I dedicate all this code, all my work, to my wife, Darlene, who will

// have to support me and our three children and the dog once it gets

// released into the public.

=======

// sometimes I believe compiler ignores all my comments

=======

Proves not to screw with programmers :D .

Source:Google,rachvela,stackoverflow.

Evolution in a gif

Life Animation

A cool animation on the evolution.

I found it while stumbling here

Installing Image libraries in mac

Mac does come with OpenGL and GLUT preinstalled, But when it comes to Image processing libraries , they rely on mac specific libraries. Since my project requires a cross platform structure, i had ignore the preinstalled libraries and search for cross platform libraries. When it comes to Image Procession the most popular library is OpenCV by intel

OpenCV

OpenCV logoOpenCV is very popular and it is has the similar features of image processing as Matlab Image Processing toolbox. Installation of OpenCV is pretty straight forward. There are few binary available in the net , but most of which work only for the sample program attached in the binary. So its better to compile the framework from the source.

Installation:

Step 1: Download the Source from sourceforge

Step 2: Extract the package

Step 3: Remove the spaces present in the extracted folder name (ie rename the folder to some simple name , I use OpenCVsrc)

Step 4:Open Terminal and go to path where the OpenCV is extracted

>cd <path>/OpenCVsrc

then run the shell script

>./make_frameworks.sh

Step 5: Once this is done , a new folder is created under OpenCVsrc with the name OpenCV.framework. Copy this to the framework directory.This directory is under /Library/Frameworks.

And now the framework is available under xcode frameworks to add and compile. OpenCV for mac is available only in i386 architecture. So the architecture in Xcode needs to be changed before compilation. An alternative method to install OpenCV is to use cmake.

CImg

CImg LogoCImg is a opensource Library which provides simple classes and methods to Load/save various file formats, access pixel values, display, resize/rotate/mirror/filter and draw primitives. There are loads of classes , which makes programming with cImg easier. Buts its not as powerful as OpenCV.

CImg needs no installation, just needs ImageMagick to run. Image magick takes care of the behind the scene operations on CImg.

CImg can be downloaded , the header file can be directly used to in programs. No compilation necessary.

Program Compilation

>g++ -o <Executable name> <Program name> -O2 -L/usr/X11R6/lib -lm -lpthread -lX11

ImageMagick

ImageMagick LogoImage Magic, another opensource image processing library . This is required by CImg for compilation. This has variety of features like

Format conversion, Transform , Resize , Transparency, Draw, Animation , Special effects etc.

The installation is as follows

Step 1: Download the Binaries from imagemagick or from the ftp site

Step 2:Create (or choose) a directory to install the package into and change to that directory, for example:

$magick> cd $HOME
Step 3:Next, extract the contents of the package. For example:
$magick> tar xvfz ImageMagick-x86_64-apple-darwin10.2.0.tar.gz
Step 4:Set the MAGICK_HOME environment variable to the path where you extracted the ImageMagick files. For example:

$magick> export MAGICK_HOME=”$HOME/ImageMagick-6.5.8″
Step 5:If the bin subdirectory of the extracted package is not already in your executable search path, add it to your PATH environment variable. For example:

$magick> export PATH=”$MAGICK_HOME/bin:$PATH”
Set the DYLD_LIBRARY_PATH environment variable:
$magick> export DYLD_LIBRARY_PATH=”$MAGICK_HOME/lib”
Step 6:Finally, to verify ImageMagick is working properly, type the following on the command line:
$magick> convert logo: logo.gif
$magick> identify logo.gif
$magick> display logo.gif
Program Compilation

g++ -o <Executable Name> <Program Name> `Magick++-config –cppflags –cxxflags –ldflags –libs`

OpenCV is in i386 architecture while CImg and ImageMagick are in x86 architecture. OpenCV is dependent on third party libraries like libjpeg etc for handling various file formats, so have a backup of the libraries before modifying these libraries.

Reference:

OpenCV

CImg

ImageMagick

Another 365 Tomorrow start….

Happy New Year

Wish You all a very happy new year. A quick 2009 passes bringing to the end of another decade with fun and knowledge. Its been a year of importance, starting with the end of my work to start of my education.