I discovered recently that for **SOME** prime numbers, given a consecutive prime, we can find out their indices using Euclid’s algorithm. Consider the following examples.

** Example: **Compute the index of 37 and 31

By Euclid’s Algorithm, we have:

37 = 31 x **1** + 6

31 = 6 x **5** + 1

6 = 1 x **6** + 0

Now, simply add the highlighted numbers to get 12, the index of 37. Since they are consecutive, 31 is the 11th prime.

** Example: **Compute the index of 29 and 23

By Euclid’s Algorithm, we have:

29 = 23 x **1** + 6

23 = 6 x ** 3** + 5

6 = 5 x

5 = 1 x

Now, simply add the highlighted numbers to get 10, the index of 29. Since they are consecutive, 23 is the 9th prime.

One final example,

** Example: **Compute the index of 23 and 19

By Euclid’s Algorithm, we have:

23 = 19 x **1** + 4

19 = 4 x ** 4** + 3

4 = 3 x

3= 1 x

Now, simply add the highlighted numbers to get 9, the index of 23. Since they are consecutive, 19 is the 8th prime.

However, the funny thing is that this doesn’t work for all consecutive prime numbers. I initially thought that this was applicable to primes with a difference of 6 until I discovered (23,19). And this is not even injective, let alone bijective. More specifically, I would love to claim that the set of all 4-difference and 6-difference pair of consecutive primes gave this beautiful result, but take (53,59) which doesn’t follow this algorithm.

I’m going to follow on this and try to come up with a pattern (maybe theorem?). I hope one of you could offer some suggestions too. In the meantime, let’s call these numbers, **“Rohan’s Numbers”, **shall we?

So it’s been 5 days since this post and I wanted to add something to it. I wrote a simple script to test my idea and here are the pairs of primes within the first 1000000000 primes that give us the index upon applying Euclid’s algorithm:

19, 23

23, 29

31, 37

43, 47

8171, 8179

479461, 479473

479497, 479509

479569, 479581

479581, 479593

189960439, 189960457.

Pretty rare!

Here is the code:

function [rohans_nums] = compute_pairs(n) % This function returns all the pairs of primes that give the index of ... % themselves upon applying Euclid's Algorithm. % % INPUT: n : First n primes within which you want to find the pairs. % OUTPUT: rohans_nums: N by 2 array of pairs where N are the number of pairs that you found clc clear all % Declare the array of primes p = primes(n); % Set variable count = 0; % Start iterations for i = 1:length(p) - 1 % Make initializations p2 = p(i); p1 = p(i + 1); a = p2; b = p1; sum = 0; % Run Euclid Algorithm while(p2>0) q=floor(p1/p2); r=p1-q*p2; p1=p2; p2=r; sum = sum + q; end % Store relevant pairs if(sum == i + 1) count = count + 1; rohans_nums(count,1:2) = [a, b]; end end end

]]>

In the fall semester of 2016, I took a course in masters level linear algebra following the text by David Lay. I had already self taught myself the basic concepts but wanted a more deeper and abstract understanding of the subject.

At first I was pretty disappointed because as the course progressed, although my concepts became more grounded, my brain was not being challenged. By the end of the course I had mastered the fundamentals and finished **5th out of 250 **in the course with minimal effort. By then end, I had gained an intuitive understanding of vector spaces, eigenspaces, linear independence, rank, basis, span, orthogonality and quadratic polynomials.

This is a subject I feel requires years of dedicated study to understand it all. With that in mind, I decided to take the advanced graduate level numerical optimization course taught by Prof Tom Goldstein(PhD, UCLA). It goes over linear programming, convex optimization and gradient descents. This course stretches the boundaries of linear algebra and enters into the non-linear realm and I can’t wait to explore this course.

My next entry will summarize what I learned in Optimization

]]>

To square a 3 digit number, here are the steps:

*Step 1:* Given a 3-digit number, round it up or down to the nearest hundred. For example, 314 would go down to 300. 567 would go up to 600. Additionally, note the amount you take to move the number to the nearest hundred, and move the given number by that same amount in the opposite direction. For example, when you moved 314 down to 300, you would also generate another number 328 by moving 314 14 units up. Similarly you moved 567 33 units up to 600. Now move it 33 units down to 534.

*Step 2:* Multiply that two new numbers that you generated in step 1. For example, you would multiply 300 by 328 and 600 by 534.

*Step 3:* Remember that amount by which you had to move the given number to make it the nearest hundred? Square it.

*Step 4:* Add the square you got to the product in step 2.

**Example:**

*Step 1:* move 17 down to reach 700 and simultaneously go 17 up to reach 734.

*Step 2:* Multiply 700 x 734 to get 513800

*Step 3:* Do to get 289

*Step 4:* Add 289 to 513800 to get 514089.

Now there are certain complications which you might have noticed if you were working along the problem as you read it. Assuming you are an intermediate at this and were able to perform step 2, it seems to many that it is *slightly difficult to keep 513800 in mind whilst simultaneously working out .* Experience has taught me that that by the time you complete step 3, you forget what you got in step 2. There are two remedies for this:

*Option 1: *Memorize the squares up to 50 (You won’t need them past 50. *why?*)

OR

*Option 2:* Use shortcuts for computing the squares.

Now, there are several famous shortcuts out there for calculating squares of two digits. In another entry, I shall be talking about a different shortcut I thought of that I could use and find it much faster and easier than the traditional ones. By employing shortcuts for step 3, it becomes easier to hold the product of step 2 in your mind and thus allows you to perform this calculation in your head.

]]>

The method in this entry is based on the following algebraic manipulation:

Using the above formula, *we reduce a multiplication problem to that of lighter multiplications followed by simple addition*. The simplicity of the formula lies in the fact that we do not have to plug in values and calculate every time. There is a pattern based on this formula and once the pattern is understood, this method becomes a much easier scenario of adding three numbers together.

From the above identity, let

After studying the formula, we infer that for A and C, no heavy calculations are needed and can be figured out almost instantly. For A, you multiply the first digit by its successor and append two zeroes. For C, you figure out its distance from 10 and square it. For B, it will take some to practice and get the hang of it but after a while one can see that all we are doing is first taking and multiplying it with 10 and doubling it. We then figure out how far is from and multiply it with that distance.

This will become clear through the following two examples:

**Example 1**

*Step 1*: Find A: Multiply 6 and 7 and append two 0’s to get 4200. Find C: The unit’s digit is 8, so squaring the distance from 10 that is 2 gives you 4.

*Step 2*: Find B: Take 7 and multiply it first by 10 and then by 2 to get 140. 68 is 3 units awayfrom 65. So multiply 140 by 3 to get 420.

*Step 3*: Add A, B and C to get the final answer. 4200 + 420 + 4 = 4624.

**Example** **2**

*Step 1*: Find A: Multiply 4 and 5 and append two 0’s to get 2000. Find C: The unit’s digit is 6 which is 4 units away from 10. So gives you 16

*Step 2*: Find B: Take 5 and multiply it first by 10 and then by 2 to get 100. 46 is 1 unit away from 45. So multiply 100 by 1 to get 100.

Step 3: Add A, B and C to get the final answer. 2000 + 100 + 16 = 2116.

This method works when . For , we simply use the deviation method which can be found here.

]]>

A fun and intriguing math performing trick is the “find the missing digit” trick. The mathemagician asks you to think of a number N preferably long, 5 or 6 digits. He will not know this number. He asks you to subtract from it, the sum of the digits of N. He then asks you to call out ALL EXCEPT ONE of the digits of the answer that you got in the previous step and IN ANY ORDER. He will tell you the digit that you didn’t call out.

**Example**

Lets say audience chooses N= 264983. They subtract 2+6+4+9+8+3 = 32 from 264983. So they will end up with 264983- 32 = 264951. They call out… 2..9..4..6..5 and leave out 1. The mathemagician will have 2+9+4+6+5 = 26 in his hand and the next multiple of 9 is 27. So he will know that the audience left out 1.

*The logic behind this trick is that subtracting the sum of digits from a number leaves the number as a multiple of 9.*

Why we try to make this a multiple of 9 is because *the sum of digits of a multiple of 9 is also a multiple of 9. *Which means that if the mathemagician has 5 of the 6 digits, he can simply check which digit would make the sum of the digits a multiple of 9.

The problem with the above method is that you need the number to be a multiple of 9 which makes this trick very specialized and the problem with most magic tricks is that once you’ve seen them enough times, they lose their charm. By attempting to generalize this particular trick, one can open the doors to whole new set of tricks. My goal is to find the missing digit when it is a multiple of not just 9, but any number like 4 or 7 or 3. For this we need to know the basics of number theory.

Let us take a start with a digit number that needs to be divisible by a number . I shall define a set of base values S = {} where

The following table shows the base numbers for 4 digit numbers for various

p | Base Numbers |
---|---|

7 | 6,2,3,1 |

17 | -3,-2,10,1 |

31 | 8,7,10,1 |

The principle will remain the same as before. In order to find the missing digit, the number of the audience should be a multiple of of our choosing. We shall use the base numbers corresponding to .

Once we have and , we’re almost good to go. Here is the caveat*. You cannot allow the audience to scramble the digits and they have to tell you which position’s digit they omit.*

Perform the following algorithm:

Step 1: Multiply the digits of the number with its corresponding base numbers. For instance, multiply the first digit by , the second digit by .. and the digit by

Step 2: Add them all up. The sum will be a multiple of .

Step 3: We check which is the nearest **next **or **previous** multiple of and figure out the missing digit either by quick observation or by using the euclidean algorithm

**Much Needed Example:**

Number: 6258 (multiple of 7). This you would make the audience end up with using some simple ‘mathemagic’ manipulations.

So you ask them to omit the 3rd digit from the right and say the rest. So they will say 6..5..8.

Step 1: Look up the table. The base digits for p=7 are 6, 2, 3 and 1. You will do inside your head, where is the missing digit.

Step 2: This equals

Step 3: we know that is a multiple of 7. What is the **next** (since we’re adding to 59)nearest multiple of 7? 63! so and that gives us the missing number 2 !

**Another Example!**

Number: 1632 (multiple of 17).

So you ask them to omit the 3rd digit from the right and say the rest. So they will say 1..3..2

Step 1: Look up the table. The base digits for p=7 are -3, -2, 10 and 1. You will do inside your head.

Step 2: This equals

Step 3: we know that is a multiple of 7. What is the **previous **(since we’re subtracting from 29) nearest multiple of 7? 17! so and that gives us the missing number 6

You will notice that the answers are pretty obvious here. That is because the base number of the corresponding missing digit is 2 which is a low number and is easy to calculate in your head. In cases where the base number of the missing digit is a large number, then the Euclidean algorithm would need to be used which I shall cover in another post.

]]>

For example, 24 x 9 would be done as 24 x 10 – 24. That is currently, the most widely known algorithm to solve this problem.

The motivation for a newer algorithm stems from the fact that the subtraction involved in the original algorithm is kind of a messy operation. As N grows larger, the process of subtraction becomes harder and eventually it becomes difficult to perform this problem in your head. For example, suppose N = 134. Subtracting 134 from 1340 while still simple, may be hard to do mentally. The algorithm I describe in this post replaces heavy subtraction with lightweight subtraction and only involves mechanical manipulation of numbers.There are a number of many other shortcuts out there but I shall be talking about a different one here.

Starting with 2 digit numbers AB, for AB × 9,

Step 1: Subtract A + 1 from AB.

Step 2: Then append 10 − B to what you get in step 1.

**Example**

With 68 × 9, simply do 68 − 7 = 61, then append 10 − 8 = 2 to get 612. For 94 × 9, you merge 94 − 10 = 84 with 10 − 4 = 6 to obtain 846.

The underlying algebra is that for a given number 10A + B, with 0 < B ≤ 9, we are computing 10[(10A + B) − (A + 1)] + (10 − B) = 90A + 9B = 9(10A + B).

Consequently, this can be applied to larger numbers. For instance, to do 123 × 9, 123 − 13 = 110 is merged with 10 − 3 = 7 to get 1107.

A similar approach can be taken when multiplying by 99. For AB x 99, subtract A+1 from 10 times AB, and then append 10 – B.

**Example**

With 87 x 99, simply do 870 – 9 = 861, and then append 10 – 7 = 3 to get 8613.

For 37 x 99, you merge 370 – 4 = 366 with 10 – 7 = 3 to obtain 3663.

The underlying algebra is that for a given number 10A + B, with 0 < B <9, we are computing 10[10(10A + B) – (A + 1)] + (10 – B) = 990A + 99B = 99(10A + B).

And finally, for multiplying with 999, for AB x 999, subtract A+1 from 100 times AB, and then append 10 – B.

**Example**

With 46 x 999, simply do 4600 – 5 = 4595, and then append 10 – 6 = 4 to get 45954. For 77 x 999, you merge 7700 – 8 = 7692 with 10 – 7 = 3 to obtain 76923.

The underlying algebra is that for a given number 10A + B, with 0 < B <9, we are computing 10[100(10A + B) – (A + 1)] + (10 – B) = 9990A + 999B = 999(10A +B).

]]>

I best describe myself as a pattern-hunter and a mathemagician. What this means is that in my spare time, I stare at sequences like squares, cubes, magic squares, sequences and series and the like and rearrange the numbers to see if I like them better. While driving, I tend to lose focus on the road, instead, split the numbers of the cars in front of me and multiply it. Over and over again till I can get to 15 cars a minute. The take away from this introduction is to never get in a car with me.

I was always known to do math differently. If the instructor was going one way about solving a problem, I would always look for other methods to reach the answer. That is what lead me to Vedic Math- a combination of speed math and mental math. Many years ago, I read the book on speed mathematics by Bill Handley. This was so long ago that they don’t print that edition anymore. Before long, not only was I studying the techniques that were taught, I began inventing my own. Some of my proud achievements are – inventing a faster method to multiply numbers by 9, 99 and 999 and so on, , proposing an alternate method to calculate cube roots, and generalizing the missing digit trick and others. However, I am neither an expert nor consider myself superior than others. I am just an enthusiast who spends a lot of time on this.

The impulsive and the impatient in the room would understand the need to do things fast. The math which they taught you in elementary school is slow and in my opinion, just taught wrong. For example, how were you taught to add two numbers? You put them on top of each other, draw a line and began adding from right to left starting from the units digit right? That is slow. By approaching the problem from the left to right you can not only do it in double the time but can also do it in your head. Before long, you will start adding stuff like 249535 + 926395 in your head in seconds. Of course, it does take practice.

As an Indian living in the United States, I have a bad habit of constantly converting dollars to Indian rupees. Mental math allows me never having to open my phone to convert $17.87. Before long, even you could be able to multiply 17.87 by 68 inside your head. Likewise, at the gym, you can use mental math tricks to convert pounds to kilos. On the road to Canada? Easily convert miles to kilometers at the drop of a hat. Convert Celsius to Fahrenheit within 2 seconds. You can do all this with mental math.

]]>