- Get a starting
- Do the update

There are certain keywords or phrases which you would have seen or heard, but not understood, such as:

- “Moving down the hill”
- “direction of steepest descent”
- “direction of lowest energy”
- your instructor would draw a ‘U-shaped’ curve and move his shiny marker down one side to the bottom…

I’ll try to demystify all of these

Before you understand GD, you must understand what smooth convexity gives you. Because understanding smooth convexity tells you what GD is actually doing and how it was derived.

**Smooth: **A function is smooth, if it’s gradient and hessian exists at all points in the domain of the function. If the gradient and hessian exists at all points of the function, then we can generate a second order taylor approximation at each point of the function. Intuitively, we can draw a quadratic (‘U-shaped’ curve) at all points of the function. The equation for this quadratic is the well – known taylor approximation:

Refer to the figure below:

**Convex: **Now that each point of the function has it’s own ‘U-shaped curve’, we further say that the entire U curve lies above the original function.

So how does this help us?

Well, think about this. You know from calculus that minimizing a quadratic is trivial. So if you take a point and its respective U curve (or quadratic approximation) and minimize that, then from convexity, that minimum will lie above your original function.

**The value at which the quadratic or U-Curve is minimized is the next iterate. Because the U-curve or quadratic is bound to exist (***Thank you Smoothness***) and the value of the function at the minimizer is ALWAYS lower than the minimum of the quadratic (***Thank you Convexity***).**

So in GD, at each update or current iteration of , what you’re essentially doing is

- Building the quadratic (or U-curve) for that current iterate:

- Finding the point that minimizes the quadratic (U-curve)

This is your .

]]>An inspection of this table reveals that each cube ends in a different digit. This

digit corresponds to the cube root in all cases except 2 and 3 and 7 and 8. In

these four cases the final digit of the cube is the difference between the cube root

and 10.

Number | Cube |
---|---|

1 | 1 |

2 | 8 |

3 | 27 |

4 | 64 |

5 | 125 |

6 | 216 |

7 | 343 |

8 | 512 |

9 | 729 |

10 | 1000 |

To see how this information is used, let us suppose

that a person calls out the cube 250047.

Step 1: The last number is a 7 which tells us immediately that the last number of the cube root must be 3.

Step 2: The first

number of the cube root is determined as follows. Discard the last three figures

of the cube (regardless of the size of the number) and consider the remaining

figures—in this example they are 250. In the above table, 250 lies between the

cubes of 6 and 7. The lower of the two figures—in this case 6—will be the first

figure of the cube root. The correct answer, therefore, is 63.

The alternate technique

My method involves presenting a different perspective to the first step of finding the last digit. For people already comfortable with the original method, this might not seem appealing as it involves a shift in their thinking and a relearning of a classical method. But for new players, this could be a chance to show that they are different.

Last Digit(D) | (0/5 +) mod 10 |
---|---|

1 | 1 |

8 | 8 |

7 | 27 |

4 | 64 |

5 | 125 |

6 | 216 |

3 | 343 |

2 | 512 |

9 | 729 |

We introduce where **{}**. Based on the above table, we generate a variable or . Depending on the location of **D** in the table, we choose which variable to use and after we fill in the value of , that variable becomes our last digit of our root.

But how do we obtain ? We solve (0 +) mod 10 or (5 +) mod 10 (depending on where D is in the table) for such that

(0 +) mod 10 = D for all D in {1,8,7,4}

(5 + ) mod 10 = D for all D in {5,6,3,2,9}

Example 1.)

Step 1: Last digit of our cube is 3. 3 is generated by solving (5+) mod 10 where 2 is the value of . So we obtain our variable 5+x = 5 + 2 = 7. This is our last digit.

Step 2: As in the usual method, after slashing the last 3 digits, we obtain 456 which is greater than 343 which is cube of 7. Thus the first digit is 7.

Hence, we arrive at our cube root of 77.

Example 2.) $49^3=117,649$

Step 1: Last digit of our cube is 9. 9 is generated by solving (5+) mod 10 where 4 is the value of . So we obtain our variable 5+x = 5 + 4 = 9. This is our last digit.

Step 2: As in the usual method, after slashing the last 3 digits, we obtain 117 which is greater than 64 which is cube of 4. Thus the first digit is 4.

Hence, we arrive at our cube root of 49.

Example 3.)

Step 1: Last digit of our cube is 7. 7 is generated by solving (0+) mod 10 where 3 is the value of . So we obtain our variable 0+x = 0 + 3 = 3. This is our last digit.

Step 2: As in the usual method, after slashing the last 3 digits, we obtain 250 which is greater than 216 which is cube of 6. Thus the first digit is 6.

Hence, we arrive at our cube root of 63.

]]>It involved the addition of three numbers, two of which were easy to get and the third required a little mental computation, but would soon get easy after practice.

In this post, I write about a different method that is even faster.

**There is one prerequisite though. You need to memorize the first fifty squares.** I know. Seems ridiculous. But if you think about it, you already know the squares till 30. It doesn’t take long to get the next 20 in memory, trust me.

A two digit square would result in the following four digit answer:

_ _ _ _

What if I told you, once you get the first 50 squares down in memory, that there was a way to **instantly** get the last two digits from memory and the first two digits would require **light-weight computation. **

That is the point towards which mental math tries to converge. Coming up with algorithms where you fill in the digits of the answer with *minimal *computation is the goal.

**EXAMPLE:**

STEP 1: GET THE LAST TWO DIGITS

Immediately get the complement of 67, that is, 33. From memory (Remember, it requires that you know the squares till 50), recall that .

The last two digits of your answer are the same as the last two digits of the square of the complement.

Thus, so far you have:

_ _ 8 9

STEP 2: GET THE FIRST TWO DIGITS

The first two digits of your answer is the first digit squared plus a number. All this step would be doing is figuring out what that number is. So you already know your first two digits is 36 + .

Multiply the two digits of your number and double it. You get 6 x 7 x 2 = 840. You don’t need this entire number. You just need the first digit. If it’s 9 or above 9, your x is this first digit (or first two digits in case of a four digit number) plus 1. If it is below 9, your x is simply that first digit.

Here, we simply do 36 + 8 = 44.

Thus, our answer is :

4 4 8 9

**This is what went through my mind when I was doing the calculation:**

1.) “Okay, 67… complement 33..okay…square is 1089 so… _ _ 8 9”

2.) “Now, 67 is .. 6 x 7 is 42 .. times 2 is 8 hundred something… (below 9).. so 36 + 8 is 44.. okay .. so we have 4 4 8 9“.

**ANOTHER EXAMPLE (as it goes through my head):**

1.) “Okay, 79… complement 21…square is 441 so… _ _ 4 1”

2.) “Now, 79 is .. 7 x 9 is 63 .. times 2 is 12 hundred something… (above 9).. so 49 + 12 + 1 is 62.. okay .. so we have 6 2 4 1“.

P.S. I am providing a more rigorous mathematical formulation for retrieving the first two digits in case it’s unclear from the method above:

FIRST TWO DIGITS

Suppose the problem is . __Your first two digits are + x .__

__To compute x__, first multiply the two digits. do A x B = AB.

1.) If AB > 50, x = 2A + 1

2.) If AB < 50, do 2 x AB

a.) If the first digit of 2AB = 9, x = 9 + 1 = 10.

b.) Else, x = first digit of 2AB.

END

]]>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.

]]>