# THE BASIC DIFFERENTIATION RULES
# https://www.mathbootcamps.com/power-rule-derivatives/ = power-rule-derivatives
# https://www.dummies.com/education/math/calculus/the-basic-differentiation-rules/ for dummies

# The constant rule
 f(x) = 5 # 5 is a horizontal line with a slope of zero, and thus its derivative is also zero

# The power rule
 f(x) = f^5
# To find its derivative take the 5 power, pull it to the front and reduce the power by 1 thus
  f(x) = 5f^4 # derivative

# Negative power
  f(x) = x^-2
# negative power derivative
 f(x) = 2x^-3 # pull power in front and reduce power by 1 , this ^-2 becomes ^-3

# find the derivative of the function
 y = 2x^4 - 5x^2 + 1
# enclose in brackets
 y' = (2x^4)' - (5x^2)' + (1)'
# factor out coefficients
 y' = 2(x^4)' - 5(x^2)' + (1)'
# apply the power rule
y' = 2(4x^3)' - 5(2x^1)' + (0) # note the constant rule of 1, 1 is a line with a slope of 0 and derivative also 0
# answer is to now simplify
= 8x^3 - 10x

# Find the derivative of the function
y = 5x^3 - 3x^2 + 10x - 8
# enclose in brackets
y' = (5x^3)' - (3x^2)' + (10x)' - (8)'
# factor out the coefficients
y' = 5(x^3)' - 3(x^2)' + 10(x^0)' - (8)' # note - since x is byitself we can write 1x^0 anything > 0 to the power of 0 is 1
# apply the power rule
y' = 5(3x^2)' - 3(2x^1)' + 10(x^0)' - (0)' # note the constant rule of 8, 8 is a line with a slope of 0 and derivative also 0
# now simplify
= 15x^2 - 6x + 10x

# find the derivative of the function
y = 2/x^4 - 1/x^2

# apply rule of negative exponents
y = 2x^-4 - x^-2

# enclose in brackets
y = (2x^-4) - (x^-2)

# factor out the coefficients
y = 2(x^-4) - (x^-2)

# power rule
y = 2(4x^-4-1) - (2x^-2-1) # OR reduce by 1 = 2(4x^-5) - (2x^-3)

# simplify
 -8x^-5 + (2x^-3)
 = 8 / x^5 + 2 / x^3 # only negative terms go to the bottom

 # Derivatives of functions with radicals (square roots and other roots)
 # You can differentiate radical functions by rewriting them as power functions and then using the power rule.
 f(x) = 3 sqrt(x^2)
 # rewrite as
 f(x) = x^2/3

 # find the derivative of the function
 y = 4 sqrt(x) -6 3 sqrt(x^2)
# rewrite function using algebra
y = 4x^1/2 - 6x^2/3
# enclose in brackets
y = (4x^1/2) - (6x^2/3)
# factor out the coefficients
y = 4(x^1/2) - 6(x^2/3)
# power rule
y = 4(1/2x^1/2-1) - 6(2/3x^2/3-1) # note ^2/3 becomes 1/3 as subtract from numerator
y = 2x^-1.5 - 4x^-1/3
# convert to fraction pulling negative exponents to the bottom
y = 2 / x^1.5 - 4 / x^1/3

= 2 / sqrt(x) - 4 / 3 sqrt(x)

# power rule is then used in the chain rule and quotient rule etc...

# https://www.mathbootcamps.com/the-product-rule/ - Product rule


# tomorrow 5.14.2019

# https://www.mathbootcamps.com/the-chain-rule/ - chain rule
# chain rule
f'(x) = ( g(h(x)))' = g'(h(x)) h'(x)

# g = outside function
# h = inside function
""" to find the derivative of f(x) then you can do this by taking the derivative of outside function g and then multiplying it by its derivative of the function h.
In other words you are finding the derivative of f(x) by finding the derivative of its pieces
"""

# Examples of applying the chain rule
""" as we apply the chain rule we will always focus on figuring out what the outside and inside functions are
"""
# find the derivative of the function
f'(x) = (3x +1) ^5
# inside function = 3x + 1
# outside function = ^5

""" you know by the power rule that the derivative of x^5 = 5x^4
So, cover up that 3x+1, and pretend it is an x for a minute. The only deal is, you will have to pay a penalty. Since it was actually not just an x, you will have to multiply by the derivative of the 3x+1
"""

# Step 1 = keep the inside
# Step 2 = take the derivative of the outside
# step 3 = multiply inside by derivative of the outside
f'(x) = 5(3x +1)^4 (3x +1)'
f'(x) = 5(3x +1)^4 (3)

# simplyfy
f'(x) = 15(3x + 4)^4  # when multiply the inside by the outside = 5 * 3 = 15 then that leaves the x and x * 3 = 3x and 1 * 3 = 1







#=============================================
# final = https://medium.com/@pdquant/all-the-backpropagation-derivatives-d5275f727f60
#=============================================
