PIL/Pillow: PIL = Python Imaging Library.

PIL is free library that allows to process images in various formats, as JPEG, PNG, BMP, etc. However, PIL's last commit was in 2011, and supports Python 1.5 only. Since there was no active development of PIL for Python3, a fork of PIL called PILLOW was released for supporting Python3. PILLOW wanted to completely replace PIL, that is why even though, we install PILLOW, we import it as PIL in python pgm. All the cmds, functions, modules etc in pillow are exactly the same as in PIL, so to end user there is no difference seen. It still looks like PIL is installed, and he can keep on working w/o any changes. All tutorials for PIL work for PILLOW also, since everything is the same. But keep in mind, that there is no PIL for python3, only Pillow. We should not install PIL, just pillow for any version of python going forward. If you had installed PIL, uninstall it, and install pillow as shown below. Keep in mind, that pillow is what we should learn, not PIL.

Pillow installation:

$ sudo python3.6 -m pip install pillow => installs Pillow as PIL. Here we are installing Pillow for python3.6

/usr/local/lib64/python3.6/site-packages/PIL/* => We see PIL dir, and lots of files under it, as well as 2 Pillow files that provides some additional info

ex: import pillow as PIL => Here we import pillow library as PIL, so that in our pgm, as just keep using PIL as if nothing changed.

Other Imaging libraries:  There are other imaging libraries as openCV, Matplotlib, etc. "Matplotlib" tis mostly for plotting, but works on images too. However, Pillow looks more complete in terms of working on most types of images, and Matplotlib documentation also says that it falls back on Pillow for cases where it doesn't have inbuilt support. So, I would invest time in learning Pillow for working on images.

Good tutorial here:

https://www.tutorialspoint.com/python_pillow/index.htm

Syntax:

Pillow library uses image class. There are lot of functions/methods that we can use on Image class.

1. methods open, save, show, resize, etc: These m ethods of class Image are used to open the image, save it, show it and to resize to some other size:

ex: test.py

from PIL import Image # Here we import Image module from Pillow library (even though we say PIL, it loads Pillow if Pillow is installed. However, if PIL is installed, then it will load from PIL, which is not what we want. So, we will have to uninstall PIL and install Pillow)

im = Image.open("images/cuba.jpg") #We use open function to load image into image class "im". We provide path starting from current dir, or we can provide the full path too.

im.show() #This shows image loaded above using show() method

im = im.rotate(45) #rotate image using rotate method

im.show() #Show rotated Image

im.save('beach1.bmp') #This saves the "im" image class as beach1.bmp (in bmp format). We can also specify the format, else it's inferred from file extension. Note that original image is still intact, as we saved with different file name.

resized_image = im.resize((round(im.size[0]*0.5), round(im.size[1]*0.25))=> this resizes the image to 1/2 for height and 1/4 for width. Or we can provide the size explicitly as im.resize(64,64). This is useful in AI, where we want to work with a standard size image.

resized_image.save('resizedBeach1.jpg') #this saves the resized image

2.  using with numpy: image class above can be used with numpy module. We can cnvert image into numpy array and vice versa. This is very useful in AI.

A. convert array into image: fromarray() => used for creating image with numpy array:

ex: below ex creates a 150 by 250-pixel array (height=150, width=250) then fill left half of the array with orange and right half of the array with blue.

from PIL import Image

import numpy as np

arr = np.zeros([150, 250, 3], dtype=np.uint8) #creates a numpy array object of shape (150,250,3) filled with all 0. The innermost triplet holds the R,G,B colors.

arr[: , :125] = [255, 128, 0] # This slicing says for axis=0 choose all range (i.e basically all rows in picture since outermost array is for rows or height). then for axis=1, it selects range from 0 to 125 (it chooses cols 0 to 100 for width. To all these array slice (which happens to be left half), it assigns RGB value as [255,128,0] which corresponds to orange

arr[: ,125:] = [0, 0, 255] #same as above, except that for axis=1, range is from 125 to max (which hapens to be right half). It assigns RGB to blue only

img = Image.fromarray(arr) #forms an image object from given 3D array

img.show()

img.save("RGB_image.jpg")

 B. convert image into array: array() => used to extract image pixels from a picture and convert them into numpy array

ex:

im = Image.open('my_image.jpg')
image_arr = np.array(im) #returns in H X W X C

arr_image = np.array(im) # we can pass this object to numpy array func (explained in numpy module section). So, arr_image becomes a 3D array of height X width X color
print(arr_image.ndim, arr_image.shape, arr_image) => prints "dim=3 shape=(240, 160, 3) arr_image=[ [ [20 47 90] .... [45 67 102] ] ]. so this picture has 240 pixels in height, 160 pixels in width and 3 values for color corresponding to R,G,B


img = Image.fromarray(arr_image) #from above array, form the picture again
img.show() #display orig image

3. misc functions available for plenty of operations on images. Look in tutorialspoints website.

 

 

Taxes:

Taxes are the favorite topic among rich people. That is where you show your smartness. Richest people pay the least in taxes. so, if you want to save in taxes, your best bet is to get rich !!

All across the world, governments work for rich people. Actually rich people are the government. Governments print money, give it to rich people, rich people pass a tiny fraction of that to poor people, and government collects back whatever little this poor people got from rich people in form of taxes. Rich people are taxed very little, and even if they were taxed heavily, most of the money they make is anyway free money given to them by the government. So it's not like they are paying back their own earned money. Thanks to modern economics, it's good to be rich :)

When we talk about taxes, we are talking about Income taxes that you and I pay on our earnings. there are many other kind of taxes, as property taxes that we pay annually on our houses, sales tax that we pay on anything that we buy, etc.

Most of the countries of the world levy income taxes on any income that an individual makes in a given year. You are taxed only on realized income. As an ex, if you bought gold, and that appreciates in value every year, you won't be taxed on that appreciation. You will be taxed only when you sell it, and will be taxed only on the profit that you earned. I'll be talking about income taxes in USA and income taxes in India. In India taxes are very high compared to USA for the same income. In USA, you can get away with 15% Federal income taxes on $100K USD of income, as you fall into lower middle class category. But the same income in India will put you in top 0.1% of earners, and will likely result in 30% or more in income taxes.

There are 23 or so countries in the world that don't levy income taxes. However, they do levy all sort of other taxes to make up for income taxes. Many of these are oil producing countries in middle east, while some of them are tourism dependent countries. Few ex are UAE, Qatar, Kuwait, Bahamas Islands, Cayman Islands, Maldives and bunch of small countries.Taxes in some Europeon countries are as high as 70%. So, USA is in the low tax countries of the west where max tax rate is 45%. Actually, if you are super rich, you pay close to 20% in taxes.

 

Following Sections are covered:

1. USA Income taxes:

2. India Income Taxes:

3. Tax calculator

4. Filing USA taxes

2. Filing India Taxes

 

This is continuation of Elementary and Middle school maths. Here the topics are advanced. The STAAR question papers can be found for high school in the texas.gov website mentioned in Maths section.

Algebra:

We can move on to algebra 2 section for high school: https://www.mathsisfun.com/algebra/index-2.html

You may want to refresh Algebra 1 section from above website too (see in elementary maths section for details)

Functions:

Functions are a heart of algebra, as anything involving variables is a function. All real life processes are described in terms of functions, and then we solve them.

Khan Academy (Functions and Matrices): https://www.khanacademy.org/math/linear-algebra/matrix-transformations

Though some lessons from above are for Matrices, look at lessons on Functions, transformation, Inverse Functions.

A function is a relation where every domain (x) value maps to only one range (y) value. Strictly function is something that takes a set of values (called as range) and maps it to another set of values (called as range). NOTE: one "x" can have only one "y" and NOT more than one. As an ex: y=f(x)=x^2 always has only one y value for each x value. It's not possible that you plug in x=2 and you end up getting 2 y values. However, 2 x values can map to same y value, i.e both x=2 and x=-2 map to same y=4. So, y=x^2 is a function, but y=sq root(x) is not a function, as x=4 gives two y values, y=2 and y=-2. If we don't consider -ve values of sq root, then sq root becomes a function.

Inverse Function: Very important concept. A function f maps values from x to y. An inverse function [written as f-1(x) ] gets us from y back to x. Consider f(x)=x^2. Inverse function for this would be f-1(x)=√x. Let's choose x=2, then f(2)=4. Now if we apply inverse to 4, we should get 2. g(x)=√x. g(4)=2, So, g is an inverse function, i.e g(x)=f-1(x)=√x. F(x)=x is an identity function, as values remain same on transformation. It's inverse is also same, f-1(x)=x. Any given function has a unique inverse function, i.e it can't have more than one inverse function.

Mathematically f-1(f(x))=x and f(f-1(x))=x

In other way to visualize, functions are deviation from the line y=x, and inverse functions are deviations from that same straight line, but in opposite direction.

FIXME: upload hand drawn diagrams.

 


 

Polynomials:

We looked at algebraic expressions (i.e xy+2ab+4, etc) in the elementary maths section.

Each of xy, 2ab, 4 is a term. So, there are 3 terms in this expression above.

Terms are separated by +/-. anything  separated by mult or div is not a term. If there is 1 term, it's called a monomial, 2 terms is called binomial, 3 terms is called trinomial, and so on. This whole family of terms is called polynomial. So, monomials are polynomials with only 1 term, binomial are poly with 2 terms and so on. NOTE: terms can only be counted once we have reduced the expression to a sum of product form with no parentheses remaining.

Degree of a poly: The greatest power or exponent of a polynomial is called its degree. So, x.y + a+5 has a degree 2, since it's first term has 1 power from x, and 1 power from y. Note that we add exponents within a term, even though the var are different and they can't be added. The reason we do that is because Degree of a poly refers to how fast the function is exponentially inc or dec. So, even if x and y are diff var, but func itself is moving at the rate of square (i.e if y is made same var as x, then it becomes x^2). Poly with degree of 2 is called Quadratic.

Polynomials are very important class of equations, and almost everything that is modeled in real life is expressed as polynomials. In fact, it has been proved that any complicated shape can be expressed as a polynomial. Each power of x has a constant multiplied with it called as "coefficient"

Addition/Subtraction: Polynomials can be added/subtracted. Only the terms with the same power of x can be reduced by adding/subtracting.

ex: 5x^2 + 2x + 7 + 9x^2+5x+5 = (5x^2+9x^2) + (2x+5x) + (7+5) = 14x^2 + 9x +12

Multiplication: Polynomials can be multiplied, by using the law of exponents explained in elementary maths section.

ex: (9x+5)*(7x^2+3x) = 9x*(7x^2+3) + 5(7x^2+3x) = 63x^3 + 27x + 35x^2 + 15x = 63x^3 + 35x^2 + 42x

Division: Division of polynomials looks tricky, but it can be done using same division method that we use for integer division. We find a multiplicand that can cancel out the term with the highest power of x. Then we move to the next highest power of x, and keep on doing so, until we are done, or left with a remainder.

ex: (2x^2+5x+7) / (x+5) => x+5 | (2x^2+5x+7) | 2x => x+5 | (2x^2+5x+7) | (2x-5) with remainder 32. We can check the answer by multiplying (x+5) and (2x-5). That gives: 2x^2+5x-25. If we add remainder of 32, then we get the original term: (2x^2+5x+7)

Other way to solve this is to divide the numerator in chunks of (x+5). i.e [ 2x(x+5) -5(x+5) +32 ] / (x+5) = 2x(x+5)/(x+5) -5(x+5)/(x+5) +32(x+5) = 2x - 5 + 32/(x+5)

ex: (3x^2+6x)/(x+2) =3x(x+2)/(x+2) = 3x

 

Power and Exponential Function:

We looked at power functions (X^2, x^3) etc.

Draw plots of power exp, root and log. FIXME

 

Plotting of Y vs X:

We looked at plotting of eqn of straight line in elementary school maths. High schools expands on that basic knowledge to plot more complicated shapes. We can plot polynomials too, though they are harder to plot. High school limits plotting polynomials to degree=2, which is quadratic equations. We also learn to plot exponential functions here. I've 2 plots below.

Plot 1: This details plotting straight line (linear function) and a curved u shaped line (quadratic function).

Plot of linear and quadratic functions

Plot 2: This details plotting simple exponential functions.

Plot of exponential functions

 

 

Algebraic Formula:

There are Formula for algebraic expression that help us in solving more complicated expressions by reducing or expanding them. Some common ones are:

  • (a + b)2 = a2 + 2ab + b2
  • (a – b)2 = a2 – 2ab + b2
  • a2 – b2 = (a – b)(a + b)
  • (a + b)3 = a3 + b3 + 3ab(a + b)
  • (a – b)3 = a3 – b3 – 3ab(a – b) 
  • a3 – b3 = (a – b)(a2 + ab + b2)
  • a3 + b3 = (a + b)(a2 – ab + b2)

Ex: To solve 57^2-43^2 => we can use identity a2 – b2 = (a – b)(a + b) => (57-43)(57+43)=6*100=600. If we try to solve it by taking squares, it will take lot longer.

Ex: To solve 57^2+43^2 => we can use identity  (a + b)2 + (a - b)2 / 2 = (a2 + b2) => ( (57+43)^2 + (57-43)^2 ) /2 = 100^2 + 6^2 / 2 = 100036/2 = 500018

Binomial Theorem:

This is a generalization of (a+b)^n where n is any +ve integer n > 0.

Link: https://en.wikipedia.org/wiki/Binomial_theorem

Theorem was generalized by Newton to allow any real number n. Here (n r) is redefined as falling factorial, since factorial is only defined for integers. It was further generalized to allow complex numbers for x,y.

{\displaystyle (x+y)^{n}=\sum _{k=0}^{n}{n \choose k}x^{n-k}y^{k}=\sum _{k=0}^{n}{n \choose k}x^{k}y^{n-k}.}

Multinomial Theorem: The identity above is generalized to have more than 2 variables, and is called multinomial theorem.The general version (for +ve integer n > 0) is:

{\displaystyle (x_{1}+x_{2}+\cdots +x_{m})^{n}=\sum _{k_{1}+k_{2}+\cdots +k_{m}=n}{\binom {n}{k_{1},k_{2},\ldots ,k_{m}}}x_{1}^{k_{1}}x_{2}^{k_{2}}\cdots x_{m}^{k_{m}},}

 


 

Equations:

We looked at solving equations of 1 and 2 variables in the elementary maths section. We looked at linear equations there. Now we look at equations which are not linear in x and y, but have higher powers.

Equations of 1 variable:

Higher powers of x: Here x has higher powers to it. So, it's a polynomial in x. These equations don't have 1 solution for x, but multiple solutions. It has been proved that equation with powers of 2 (i.e x^2) have 2 solutions, x^3 have 3 solutions and so on. It has been proved that polynomial with power n, have n solution, which are called the n roots of the polynomial.

It's the Fundamental theorem of Algebra and applies to coefficients with complex coefficients too:  https://en.wikipedia.org/wiki/Fundamental_theorem_of_algebra

Finding n roots of any polynomial of degree n is not easy, but we know the relation b/w these n roots (roots may be real or imaginary, and may be repeated or unique) via Vieta's Formula: https://en.wikipedia.org/wiki/Vieta%27s_formulas

Complex numbers are explained in advanced Maths section.

We know how to solve x^2, but higher powers of x are harder to solve, and above formulae is used for solving it. Student is not expected to solve those, so we'll just concentrate on x^2 and x^3 (Degree of 2 and 3 are really popular questions in Maths olympiads).

Quadratic Polynomial (Power of 2): ex: x^2 + x = 5. This is called a quadratic equation. This can be solved via 2 ways:

1. Solving by using formula: It can be solved by using the formula for a*x^2 + b*x + c =0.Teach the kid how to derive that formula.

Derivation is not that hard: Look here: https://www.mathsisfun.com/algebra/quadratic-equation-derivation.html

An alternate way to solve is by using the same method as the derivation above. So, solve by making a square in form of (Ax+B)^2 -D + C  = 0. Now bring numbers on RHS, take a square root, and solve for x.

ex: 2x^2+4x - 6 =0 => 2 (X^2 + 2x - 3) =0 => (x+1)^2 - 1 - 3 =0 => (X+1)^2 = 4 => (x+1) = +2,-2 => x=1,-3. So, this is exactly how quadratic eqn solution was derived above.

2. Other way to solve it is to bring it into the form a(x-p1)(x-p2)=0 where p1,p2 are the two solutions (or the 2 roots). There are 2 cases to consider.

  1. When coeff "a" = 1: Then x^2 - (p1+p2)*x + p1*p2 = 0. So, -b/a = the sum of the two roots = p1+p2, while c/a = product of 2 roots = p1*p2. This is a very important property used in factorizing the middle term. When p1,p2 are integers, then it's easier to find 2 such integers that will work. We can't rely on factorizing this if solution involve decimals. NOTE: IF the roots are p1 and p2, then the factors are -p1 and -p2. Since, -p1 + -p2 = b and (-p1)*(-p2)=c, for factorizing, we need to find 2 numbers such that their sum is b and product is c. Then the roots will be negative of those numbers, i.e if the factors are 2,3, then roots will be -2, -3. Important to remember this.
    1. ex: x^2 - 5x + 6 =0 => x^2-3x-2x+6=0 => x(x-3) - 2(x-3) =0 => (x-3)(x-2)=0 => 2 soln for this eqn: x=2 or x=3 (p1+p2=-5, p1*p2=6) => We are looking for 2 numbers whose sum is -5, but whose product is 6. One such pair of numbers is -2,-3. So, we get 2 factors as -2,-3.
  2. When coeff "a" ≠ 1: Above method of factorizing needs to be modified. We can always reduce such eqn to form where a=1 (by dividing whole quad eqn by a"), but then the coeff, b and c may become non integers, which is harder for humans to factorize. If roots are p1, p2, then a*[x^2 - (p1+p2)*x + p1*p2] = 0. Here a*(p1+p2)=-b, and a*p1*p2=c. So, the 2 roots p1, p2 satisfy p1+p2=-b/a and p1*p2=-c/a. What about the factors? Middle coeff "b" needs to separated into 2 terms -a*p1 and -a*p2 s.t (a*p1 + a*p2 = b), and (-(a*p1)*-(a*p2)=a*(a*p1*p2)=a*c). So, 2 factors are such that their sum is b, but their product is a*c. So, the 2 factors are -(a*p1) and -(a*p2), and the roots are p1, p2. Once factors are found, roots can be found by dividing the factors by -a.
    1. ex: 10*x^2-9*x+2=0 => Here we are looking for 2 numbers s.t their sum is -9 and their product is 10*2=20. 2 such numbers are -4 and -5. So factors of middle term are -5x, -4x => 10*x^2 - 5*x - 4*x + 2 =0 => 5*x(2x-1) - 2(2*x-1)=0 => (2*x-1)(5*x-2)=0 => The 2 roots are x=1/2, 2/5. This can also be solved for roots by dividing whole eqn by 10, and then looking for 2 numbers such that p1+p2=-9/10, p1*p2=2/10. One such pair is -4/10, -5/10. But it's much harder to see this as it's in fractions. So, we do it the other way suggested, as that keeps the 2 numbers as integers. The 2 roots can be found from the factors by dividing b -a=-10. So, 2 roots are -4/-10, -5/-10 = 2/5,1/2.

Solving for these eqn the other way round is lot easier. i.e eqn with form (x-2)(x-3) is lot easier to expand than solving eqn of form x^2 - 5x + 6 =0.

Cubic Polynomial (Power of 3): ex: x^3 + x^2 + x = 5. This is called a cubic equation. This is harder to solve. We can solve to by using Vieta's Formula to get relation among the 3 cubes which states:

For the 3 roots of a*x^3 + b*x^2 + c*x + d =0, p1+p2+p3 = -b/a, p1*p2 + p2*p3 + p1*p3 = c/a, p1*p2*p3 = -d/a.

Putting in the 3 roots => a*(x-p1)*(x-p2)*(x-p3)=0

Again, 2 ways to solve it, as in quadratic formula above. There are 2 cases to consider.

  1. When coeff "a" = 1: This is easy and same as quadratic case. Find 3 integers whose sum is -b, and product is -d. Those will be the roots. One way to solve it by guess, and see if you can get values for p1, p2, p3 (provided p1, p2, p3 are integers). Easy to find all possibilities of such integers, as there aren't too many combo possible.
  2. When coeff "a" ≠ 1: This gets harder. If roots are p1, p2, p3, then a*(x-p1)*(x-p2)*(x-p3)=0 => a*[x^3 - (p1+p2+p3)*x^2 + (...)x + p1*p2*p3] = 0. Here a*(p1+p2+p3)=-b, and a*p1*p2*p3=-d. Middle coeff "b" needs to separated into 3 terms -a*p1, -a*p2 and -a*p3 s.t -(a*p1 + a*p2 + a*p3 = b), and (-a*p1*-a*p2*-a*p3=-a*a*(a*p1*p2*p3)=a*a*d). So, 3 factors are such that their sum is b, but their product is a*a*d (NOTE the a^2 term here instead of 1 term in quadratic eqn). The factors are -a*p1, -a*p2, -a*p3, and then we can get thr roots by dividing the factors by -a.
    1. ex: 10*x^3 - 39*x^2 + 29*x - 6 = 0 (AMC 12 Maths Olympiad 2022). => Here we are looking for 3 numbers s.t their sum is -39 and their product is 10*10*-6=-600. Factorizing 600, we get 600=2^3*3*5^2. If we choose 3 factors as -30, -5, -4, then we see that we get  3 such numbers. So, 3 roots are obtained by dividing these factors by -a = 30/10, 5/10 and 4/10 = 3,1/2,2/5.
    2. There is another way to solve the above cubic poly. Expand x^2 coefficient and x coefficient into 2 components and then get 1 root. The other 2 roots will come from the quadratic eqn that we know how to solve. We ignore a for now, and assume a=1. Here we see that sum of these modified roots is 39, while product of these modified roots is 6. So, roots may be 1,1,6 or 2,3,1. We take 1 root as 3, then we break coeff 39 into 2 parts such that 1 factor is 3. If one part is 30, then we get 3 as a root => 10*x^3 - 30*x^2 - 9*x^2 + 27*x + 2*x - 6 =0 => 10*x^2(x-3) -9*x(x-3) + 2(x-3) =0 => (x-3)(10*x^2-9*x+2)=0. So 1 root is 3. The other 2 roots are from quadratic eqn 10*x^2-9*x+2=0, This has been solved above for roots=1/2, 2/5. This method works only because one the roots happened to be an integer. If all 3 roots were non integers, then this method won't work. It's a quick and dirty visual way to break components into factors.

Radical equation (power of 1/2 or square root, cube root, etc): ex: √(x+2) = 4. These are little tricky to solve. We solve them by converting them to quadratic eqn (for sq root) or to higher powers of x (for cube roots, etc)

One way to solve these is to square or cube both sides of eqn so that sq root, cube root,, etc are gone and we are left with just x, x^2, x^3 or so on, which we know how to solve.

ex: (x+2)^1/2 = 4 => sq both sides => (x+2) = 16 => x=14.

ex: (x+2)^1/2 = -4 => sq both sides => (x+2) = 16 => x=14. Here sq root of a number is set to -ve number. Strictly speaking, x=14 is a solution for this eqn too. However, for sq root eqn, we generally mean the +ve square root solution only. The -ve sq root solution is called extraneous soln, and is generally not considered correct. That's why we should plug in our answer, to see if we get the real soln or not. We need to throw away extraneous soln, and there is no way to know which soln is extraneous w/o plugging in our solved numbers back into the original eqn.

ex: √4 = +2,-2 => This has 2 soln (squaring 2 or -2, both yield 4). However, when we say sq root, we generally mean +ve sq root, so +2 is the real soln, and -2 is extraneous soln which is not considered correct.

NOTE: I'm guessing the reason we don't consider both +ve and -ve soln for √X is because √X won't be a function anymore, i.e for any value of X, we'll have 2 Y, which isn't a function.

Here's a link to solve radical eqn: https://www.mathsisfun.com/algebra/radical-equations-solving.html

 

Equations of 2 variable:

Higher powers of x and y: Here x and y have higher powers to them. These are even harder to solve, so calculus or computer programs are used to solve it. Depending on powers of x and y, they can have more than 1 solution.

ex: x^2 + y^2 = 13, x^3 + y = 19

Equations of more than 2 variables: Here we have n variables, as x, y, z. We can have linear or higher powers. These are also not expected to be solved by hand, except may be simple linear equation of 3 var  = x, y, z.

ex: x+y+z=34, x+2y+z=38, 2x+y+z=44 => We can solve these 3 equations the same way we solve for 2 equations.

 


 

Series:

Arithmetic Series or Arithmetic Progression (AP): This is a series of number where each number differs from the next one by a constant number.

ex: 1, 5, 9, 13, ... => Here the difference between consecutive numbers is 4

finding sum of AP with n numbers, where a=1st number, and d=difference. i.e a, a+d, a+2d, a+3d, ... a+(n-1)d

Sum = a +     (a+d)           + (a+2d) + ....+  (a+(n-1)*d)

Sum = a + (a+(n-1)*d)    +  ....                + (a+d)

=> 2*Sum = 2*a + (2*a+n*d)*(n-1)

=> 2*Sum = 2*a*n + n*d*(n-1)

=> Sum = n*[a + (n-1)*d/2]

ex: For simple AP series of S=1+2+3+...+N => Here a=1, d=1, n=N

=> S=N*[1+(N-1)/2] = N*(N+1)/2

Geometric series or Geometric Progression (GP): This is a series where the ratio between consecutive numbers is constant

ex: 1, 4, 16, 64, ... => Here the ratio between consecutive numbers is 4

finding sum of GP with n numbers, where a=1st number, and r=ratio i.e a, a*r, a*(r^2), a*r^3, ... a*(r^(n-1))

Sum = a +     (a*r)           + (a*r^2) + ....+  (a*r^(n-1))

r.Sum =          (a*r)           + (a*r^2) + ... + (a*r^(n-1)) + (a*r^n)

=> Sum - r.Sum = a - (a*r^n) => NOTE: all other terms cancel out

=> Sum(1-r) = a(1-r^n)

=> Sum = a(1-r^n) / (1-r)

ex: For simple GP series of S = 1 + 2 + 4 +8 + ... 2^N => Here a=1, r=2, n=N+1

=> S=1*(1-2^(N+1))/(1-2) = 2^(N+1)-1 => This summation is very useful in Binary number conversion to decimal in computer science

Sum of squares of first n numbers: This is proved by induction to be n(n+1)(2n+1)/6 (see in advanced math section for proof).

W/O induction it's hard. However a neat technique exists.

(n+1)^3 - 1^3 = 3n^3+3n^2+3n

Summation from i=1 to i=N for the expression Σ[(i+1)^3-i^3] will simply be (N+1)^3 - 1^3 as all terms in the series cancel out with each other (since we are subtracting the next number as well as adding the next number). => call it eqn (1)

However, if we simply expand (i+1)^3 into constituent terms, we can also write above expr as  Σ[(i+1)^3-i^3] =  Σi^3 + Σ3*(i^2) + Σ3*i + Σ1 - Σi^3 = 3Σ(i^2) + 3Σi + Σ1 = 3Σ(i^2) + N(N+1)/2 + N => call it eqn (2)

Eqn (1) and (2) are same. So, equating them, we get => (N+1)^3 - 1^3 =  3Σ(i^2) + N(N+1)/2 + N 

=> N^3+3N^2 + 3N = 3Σ(i^2) + N(N+1)/2 + N 

=> 3Σ(i^2) =  N^3+3N^2 + 3N - N^2/2 - 3N/2 

=> 3Σ(i^2) =  N^3+3/2*N^2 + N/2 

=> Σ(i^2) =  1/3*[N^3+3/2*N^2 + N/2] = N/6*(2N^2+3N+1) = N/6*[(N+1)(2N+1)] => which is the same formula as above

Sum of cubes of first n numbers: This is proved by induction to be [n(n+1)/2]^2 (see in advanced math section for proof). It's just square of sum of 1st n numbers.

To find the formula itself for cubes, we can use the same technique as above. Little longer, but nothing different.

Sum of ith power of first n numbers:There is a general formula involving Bernoulli's numbers and coefficients. Ask ChatGPT for formula.

 


 

Simple and Compound Interest:

This is a topic that is introduced in Elementary maths, but I included it here, since compund interest requires solving eqn with higher powers of X.

Simple Interest: Introduce the concept of principal and interest when money is deposited in a bank. Introduce the concept of rate per annum, as well as per quarter, per month, or rate per day. It should be clear that all these rates mean different effective rate.

SI for T years = P*(R/100)*T => Where P=principal, R=rate in % p.a, T=total time in years

Total Principal after T years = P *( 1+R*T/100)

Compound Interest: Compound interest is the compunded interest, where you get interest on the interest too. This seems more fair, since if the bank didn't give you interest on your earned interest, then you scould withdraw that interest, put that interest amount in other bank, and start earning earning interest on that.

CI for 1st year is same as SI for 1st year, if interest rate is per annum

CI (for 1st year) = P*(R/100)

A1 = Total Principal after 1 year = P *( 1+R/100)

CI (for 2nd year) = A1*(R/100)

A2 = Total Principal after 2 years = A1+ A1*R/100 = A1*(1+R/100)

CI (for 3rd year) = A2*(R/100)

A3 = Total Principal after 3 years = A2+ A2*R/100 = A2*(1+R/100) = A1*(1+R/100)^2 = P*(1+R/100)^3

Similarly AT = Total Principal after T years = P*(1+R/100)^T

So, Total Principal after T years = P *( 1+R/100)^T

Conclusion: As can be seen above, CI is more than SI for any year after the 1st year, and total Principal with compound interest is lot more than that with simple interest.

 


 

Matrix:

Matrix is one the simple topics, but rather important one to learn. The usage of matrix is not apparent, as it's just a way of representing numbers. Matrices are widely used in computer programming to rep a large set of numbers, and operate on them efficiently.

Good material here: https://www.mathsisfun.com/algebra/matrix-introduction.html

Various operations of +, -, *, / are explained on link above. Most interesting is the multiplication of 2 matrices which is known as the "dot product" of 2 matrices. Most important thing to remember about matrix multiplication is that:

To multiply an m×n matrix by an n×p matrix, the ns must be the same, and the result is an m×p matrix.

i.e (mXn) dot (nXp) = (mXp) matrix

So ... multiplying a 1×3 by a 3×1 gets a 1×1 result. But multiplying a 3×1 by a 1×3 gets a 3×3 result.

NOTE: Terms "Multiplication of 2 matrices" and "Dot product of 2 matrices" are used interchangeably. It's OK to use them with the understanding that multiplication is actually dot product. Multiplication of a matrix with a scalar is simply multiplying each entry of the matrix with that scalar. So, be careful when you see these terms.

 


 

Advanced:

Advanced maths topics on Limits, calculus, etc are in next section. I'll start that section in some time. Note that if you are preparing for SAT exam, then everything until is point is all you need. SAT Maths don't need you to know any advanced stuff about calculus, etc. Basic linear and quadratic equation solution, and basic High school maths can easily fetch you 100% score in SAT Maths.

 


 

Indian Population and Economy:

In India, there are about 250M households (as of 2011, implying 5 people per household which is 3rd highest in the world), of which 140M households (comprising 700M people) are deprived and earn less than $2K/year. That implies less than $5/day for these poor people to feed a family of 5 (implying feeding on less than $1/day). Next 75M households (comprising 400M people) make between $2K-$5K per year. Again, less than $15/day for whole family to feed. In essence, 80% of the population earns less than $1/hour and feeds on less than a $1/day. As per World Food Programme (WFP), 25% of population is in extreme poverty earning less than $2/day. About 800M are poor, and gap between rich and poor is widening as fast as the economy is growing. Next 30M households is the so called middle class, which comprises of 160M people. They make between $5K - $30K and will definitely be considered poor in any western country. That brings us to top 1% of country who are considered rich. These are 3M households comprising 15M people.

https://desiparinda.files.wordpress.com/2014/08/6a00d8341dd33453ef0147e3b81a02970b.png?w=560

As of 2015, about 4 crore (or 40M) Indians filed Income tax returns of which 2 crore paid taxes (meaning they had an income of over $5K). That implies that about 10% of households paid income taxes (population wise, it's just 3% of population). Total number of crorepaties (people making over $200K/year) was 50K only. In contrast, in USA about 15M people make more than that per year. Total income was 35L crore declared on these income tax returns (approx $0.7T assuming $1=Rs50). Companies filed about 1M returns with gross income of Rs. 11L crore ($0.2T).

http://www.indpaedia.com/ind/index.php/Income_Tax_India:_Statistics

 

 

This section deals with Retirement in terms of money and NOT in terms of age.

Retirement refers to Financial freedom. So, why would anyone want to get financial freedom? First of all, you should have the freedom to do anything you want to do, and say NO to things you don't want to do. As I discussed earlier in other articles, most of the people are part of the fake economy, where they get out of their house everyday to dig up a hole for half the day and then fill up that hole for the other half of the day. Why spend your labor doing something that produces nothing? Instead of doing that, you would be better enjoying the life God has given us.

I'll talk about all the strategies that you can use to save enough to achieve financial freedom.

When we talked about GDP, we said that US GDP grows by about 5% a year, and it reflects the total amount of money growth in the system. So, any money you invest anywhere has to grow by 5% every year, just to keep up with the money growth. I think of GDP growth (minus the population growth) as real inflation.

There are 3 places where you can invest in order to grow your savings:

1. Banks: Depositing money in banks is a sure way to lose money every year. With interest rates at 0%, you lose about 5% of your principle amount every year, since GDP grows by 5% a year. So, in 30 years, $1 deposited in bank is reduced to 10 cents when real inflation is considered. Chances are very high that deposit rates may go negative in future (as of 2020, it's still positive). Read in "Banks" section for more details.

2. Bonds: Instead of lending money to banks, you lend it to institutions or private companies. Of course the rate you get here will be higher than what you can get by depositing money in banks, but the money is not insured by FDIC or any other agency. So, if the private company goes bankrupt, almost all of your prinicipal is gone. Read in "Bonds" section for more details.

3. Housing: Housing is one area which has put even "Warren Buffet" to shame. The return that anyone in USA can get in housing is more than what Warren Buffet ever made on any investment in his life. This insane return in housing market (with leveraged money) has been going on for a decade, and with Government supporting housing forever, I don't see how it can burst, unless "FED" is abolished al together. Read in "Housing" section for more details.

4. Stocks: This is my favorite part. This is the mother of all Ponzi schemes and is run by an arm of Govt itself, known as "FED". See in Stocks section on why this Ponzi scheme will run for as long as there is a money printing entity. If this crashes, then housing will crash too, along with all the other assets too. So, if you have to invest in a Ponzi scheme, invest in one that is the mother of all, as it drives all other ponzis. That will be the last one to fail.

Now that we have figured out that stocks are the best investment vehicle for our future returns relative to GDP, let's explore the strategies for retirement in next few sections.