Monday, September 1, 2008

Square Architecture - Square Any Number Easy Way

While nothing interesting going on in the software world, I got to play with some Math tricks, and got interested in ancient Indian math called Vedic Mathematics. While learning some of it, I thought of writing about this particular method-

Finding Square of Any Number using Vedic Math

The formula is called Dwandwa-yoga (Duplex combination process). Let's see how it works.
Duplex (D) of a number is found as follows, examples later will make it more clear.
For Duplex, in the number sequence we have to find square of, we take twice the product of the outermost pair, and then add twice the product of the next outermost pair, and so on until no pair is left.
When there are odd number of digits in the original sequence there is one digit left by itself in the middle, then this enters as its square.

So, if the number is:

a then D -> a2
ab then D -> 2(axb)
abc then D -> 2(axc) +b2
abcd then D -> 2(axd) + 2(bxc)
abcde then D -> 2(axe) + 2(bxd)+c2
...and so on.

So, finding duplex is so easy, and after that, it is just addition, so very simple.
Before that, note that if we are given an n digit number to square, we will prepend that number with n-1 zeros.

So, let's try this. Find square of 52. It is a two digit number, so, add 2-1=1 zero in the front.

052
Now, let's find the Duplex:

For 2, D= 22 = 4
For 52, D=2(5x2) = 20
For 052,D=2(0x2)+52 = 25

So, simple, now, just add the numbers we got:

04
20
25
_______
2704

Let's try one more example: 1092
A three digit number, so we have to add 3-1=2 zeros before it.

00109
Duplex:
For 9, D=92 = 81
For 09, D= 2(0x9) = 0
For 109, D=2(1x9)+02 = 18
For 0109, D=2(0x9)+2(1x0) = 0
For 00109, D=2(0x9)+2(0x0)+12 = 1

Here we go:
81
00
18
00
01
__________
011881

Indeed, that's the answer.

Let's do an easy one: 152
015
For 5, D = 52 = 25
For 15, D= 2(1x5) = 10
For 015, D=2(0x5)+12 = 1
And,
25
10
01
________
0225 is the answer.

Now, that brings me to a special case, for even easier calculation.
The special case is - the numbers which are ending with 5. Say, the number is of the form a5. The square of that number will be = a(a+1)|52.

So, for 152, the result will be 1(1+1) | 52
i.e. 2 | 25 or 225.

Similarly, 952 will be 9(9+1) | 25
i.e. 9025.


Now, that is superfast, I am sure in some cases it is even faster than doing it on calculator.

5 comments:

Shaurya said...

The method you put here is awesome
Thank you very much.
You too are Genius .

sujeet said...
This comment has been removed by the author.
sujeet said...

sujeet ladania mbi

sujeet said...

sujeet ladania mbi

sujeet said...

very good method. its really work