Wednesday, January 15, 2014

HASKELL DIFFERENTIAL CALCULUS DERIVATIVE EQUATIONS

HASKELL DIFFERENTIAL CALCULUS DERIVATIVE EQUATIONS

REVISED: Thursday, February 8, 2024




Haskell And Derivatives.  (Note this blog is a work in progress.)

Differential Calculus cuts something into small pieces to find how it changes.

I. DERIVATIVES

A derivative is the slope of a curve, and the rate of change.

The derivative of f (x) is the function

d/dx f(x) = lim h→0 ( f(x + h) − f (x) ) / h = f'(x).

If this limit does not exist (DNE) for a given value of x, then f(x) is not differentiable at x.

Differentiability implies continuity; if f(x) is a differentiable function at x = a, then f(x) is continuous at x = a.

A. First Derivative Test

Suppose that f(x) is continuous on an interval, and that f′(a) = 0 for some value of a in that interval.

(a) If f′(x) > 0 to the left of a and f′(x) < 0 to the right of a, then f (a) is a
local maximum.

(b) If f′(x) < 0 to the left of a and f′(x) > 0 to the right of a, then f (a) is a
local minimum.

(c) If f′(x) has the same sign to the left and right of f′(a), then f′(a) is not a
local extremum.

B. Second Derivative Test

Suppose that f'' (x) is continuous on an open interval and that f' a = 0 for some value of a in that interval.

(a) If f′′(a) < 0, then f (x) has a local maximum at a.

(b) If f′′(a) > 0, then f (x) has a local minimum at a.

(c) If f′′(a) = 0, then the test is inconclusive. In this case, f (x) may or may not have a local extremum at x = a.

C. Trigonometric Function Derivatives

(a) d/dxsin(x) = cos(x).

(b) d/dxcos(x) = − sin(x).

(c) d/dxtan(x) = sec2(x).

(d) d/dxsec(x) = sec(x) tan(x).

(e) d/dxcsc(x) = − csc(x) cot(x).

(f) d/dxcot(x) = − csc2(x).

D. Inverse Trigonometric Function Derivatives

(a) d/darcsin(y) = 1/√(1-y2).

(b) d/darccos(y) = −1/√(1-y2).

(c) d/darctan(y) = 1/(1-y2).

(d) d/darcsec(y) = 1/(|y| √(y2-1)) for |y| > 1.

(e) d/darccsc(y) = −1/(|y| √(y2-1)) for |y| > 1.

(f) d/darccot(y) = −1/(1 + y2).

II. DERIVATIVE RULES

A. CONSTANT RULE

Given a constant c.

d/dx c = 0.

A constant is not changing.

B. SUM RULE

If f(x) and g(x) are differentiable and c is a constant, then:

(a) d/dx (f(x) + g(x)) = f'(x) + g'(x)

(b) d/dx (f(x) - g(x)) = f'(x) - g'(x)

(c) d/dx (c * f(x)) = c * f'(x)

The derivative of a sum is the sum of the derivatives, and the derivative of a difference is the difference of the derivatives.

C. PRODUCT RULE

Let h(x) = f(x) * g(x).

If f and g are differentiable at a, then

h'(a) = f'(a) * g(a) + f(a) * g'(a).

In other words:

d/dx(f(x) * g(x)) = (d/dx f(x)) * g(x) + f(x) * (d/dx g(x))

The derivative of a product is the derivative of the first times the second, plus the first times the derivative of the second.

D. QUOTIENT RULE

Let h(x) = f(x)/g(x).

If g(a) /= 0, and

f and g are differentiable at a, then

h'(a) = ((g(a) * f'(a)) - (f(a) * g'(a)))/g(a)2

The derivative of a quotient is the derivative of the top times the bottom, minus the top times the derivative of the bottom, all over the bottom squared.

E. POWER RULE

For any real number n,

d/dx xn = nxn-1.

Multiply by the power and reduce the power by one.

f x n = n * x ** (n - 1)

F. CHAIN RULE

If f(x) and g(x) are differentiable, then

d/dx f(g(x)) = f′(g(x))g′(x).

We identify the “inside function” and the “outside function”.  We then differentiate the outside function leaving the inside function alone and multiply all of this by the derivative of the inside function.

(a) Look for parentheses.

Dx (un)

(b) Bring exponent to front.

Dx (un) = n(un)

(c) Subtract exponent by one.

Dx (un) = n(un-1)

(d) Multiply by inside derivative.

Dx (un) = n(un-1)Dx (u)

(e) Do not have any negative exponents in answer.

(f) Answer must be as simplified as possible.

(g) √x = x1/2

(h) x-1 = 1/x  

A negative exponent in the numerator means inverse, which becomes a positive exponent in the denominator.

(i) a2 * a3 = a5 

Whenever you multiply two terms with the same base, you can add the exponents.

(j) (a 2) 3 = a6 

Whenever you have an exponent expression that is raised to a power, you can multiply the exponent and power.

(k) (xy2)3 = x3y6 

If you have a product inside parentheses, and a power on the parentheses, then the power goes on each element inside.

(l) Anything to the power zero is just "1".

III. HASKELL DERIVATIVE EXAMPLES

A. CONSTANT RULE



B. SUM RULE



C. PRODUCT RULE



D. QUOTIENT RULE



E. POWER RULE

f x n = n * x ** (n - 1)

Prelude>  let f x n = n * x ** (n - 1)
Prelude>

Prelude>  f 2 3
12.0
Prelude>

F. CHAIN RULE



IV. HASKELL DERIVATIVE THEOREMS

A. DERIVATIVE OF EX THEOREM

d/dx ex = ex

B. FERMAT'S THEOREM

If f(x) has a local extremum at x = a and f(x) is differentiable at a, then f′(a) = 0.

C. DERIVATIVE OF THE NATURAL LOGRITHM THEOREM

d/dx ln(x) = 1/x.

V. PROCEDURE FOR SKETCHING THE PLOTS OF FUNCTIONS

(a) Find the y-intercept, this is the point (0, f (0)). Place this point on your graph.

(b) Find candidates for vertical asymptotes, these are points where f (x) is undefined.

If lim x→a f(x) = ±∞, lim x→a+ f(x) = ±∞, or lim x→a− f(x) = ±∞,

then the line x = a is a vertical asymptote of f (x).

(c) Compute f′(x) and f′′(x).

(d) Find the critical points, the points where f′(x) = 0 or f′(x) is undefined.

(e) Use the second derivative test to identify local extrema and/or find the intervals where your function is increasing/decreasing.

(f) Find the candidates for inflection points, the points where f′′(x) = 0 or f′′(x) is undefined.

(g) Identify inflection points and concavity.

(h) If possible find the x-intercepts, the points where f(x) = 0. Place these points on your graph.

(i) Find horizontal asymptotes.

If lim x→∞ f(x) = L or lim x→−∞ f(x) = L,

then the line y = L is a horizontal asymptote of f(x).

(j) Determine an interval that shows all relevant behavior. At this point you should be able to sketch the plot of your function.

VI. STRAIGHT LINE EQUATIONS

A. SLOPE-INTERCEPT FORM

y = mx + b

This is called the slope-intercept form because "m" is the slope and "b" gives the y-intercept.

B. POINT-SLOPE FORM

Given a point (x1, y1) and a slope m.

y – y1 = m(x – x1)

VII. CONCLUSION

In this tutorial, you have been introduced to using Haskell to solve differential calculus derivative equations.

VIII. REFERENCES

Bird, R. (2015). Thinking Functionally with Haskell. Cambridge, England: Cambridge University Press.

Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.

Goerzen, J. & O'Sullivan, B. &  Stewart, D. (2008). Real World Haskell. Sebastopol, CA: O'Reilly Media, Inc.

Hutton, G. (2007). Programming in Haskell. New York: Cambridge University Press.

Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.

Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.