Showing posts with label Calculus. Show all posts
Showing posts with label Calculus. Show all posts

Saturday, February 21, 2015

IS ⊥ BOTTOM THE HASKELL RED-HEADED STEPCHILD?

IS ⊥ BOTTOM THE HASKELL RED-HEADED STEPCHILD?

REVISED: Thursday, February 8, 2024




Haskell And Bottom.

I. IS ⊥ BOTTOM THE HASKELL RED-HEADED STEPCHILD?

Undefined or bottom written with an up tack or falsum ⊥ refers to a computation which never completes successfully. Think of bottom as representing a computation which will not halt, it does not terminate. The glyph of the up tack appears as an upside down tee symbol, and is sometimes called eet, the word tee in reverse. Bottom or whatever you prefer to call it represents a computation which causes our program to fail. However, the ⊥ bottom type is a sub-type of all types! For example, the type Bool does not just include True, False it really includes True, ⊥, False. The type () with only one element actually has two: ⊥, (). The type Integer really includes [⊥, 0, 1, 2, 3..]. The same inclusion can be said of all types. Adding ⊥ to a set of values is called lifting. All normal Haskell types are lifted.

Why do we rarely see discussions devoted to bottom? Maybe it is related to our technological evolution. In the past we appeared to need information on large objects we could see with the unaided eye, we did not seem as interested in the very small, the bottom. Our technology has evolved, now we need information on both the very large and the very small. We need to rethink the importance of bottom. Granted Haskell does not have sub-types; however, bottom should be thought of as more than just not terminating or an error message. Seeing a bottom should spark our creative thought processes. There is more to a bottom than meets our unaided eye.

One area of creative thought processes is the math field of calculus which calculates limits and derivatives. How often have you recently seen Haskell used to solve non lambda calculus, calculus problems? These of course are problems calculating numbers approaching infinity or zero. What is infinity, is infinity bottom? What is zero? We need Haskell to help us with the creative what is ... problem types. Haskell is based on math; however, I have seldom seen easy to understand, Haskell non lambda calculus, calculus limits or derivative functions outside of Haskell Cabal. We have a lot of work ahead of us. 

I love Haskell, it is my favorite programming language; however, is the ⊥ bottom type the Haskell red-headed stepchild?

II. CONCLUSION

In this tutorial, you have been introduced to Haskell ⊥ bottom.

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




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/dy arcsin(y) = 1/√(1-y2).

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

(c) d/dy arctan(y) = 1/(1-y2).

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

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

(f) d/dy arccot(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.




Monday, January 13, 2014

HASKELL INTEGRAL CALCULUS LIMIT EQUATIONS

HASKELL CALCULUS LIMIT EQUATIONS

REVISED: Thursday, February 8, 2024




Haskell and Limits.  (Note: This blog is a work in progress.)

The word Calculus comes from Latin meaning "small stone". Integral Calculus joins in other words integrates all of the small pieces together to determine the total.

Differential Calculus and Integral Calculus are like inverses of each other, just like multiplication and division are inverses.

I. LIMIT LAWS

Given:

The lim x→a is a special way of saying, ignoring what happens when the value x gets to the value a as the value x moves closer and closer to the value of a the value x becomes a closer and closer approximation of the value of a

A limit is a value that a function approaches as the input x approaches some value.

As shown below, as x approaches a x→a then f(x) approaches L; and as x approaches a x→a then g(x) approaches M.

lim x→a f(x) = L,

lim x→a g(x) = M,

k is some constant,

and n is a positive integer.

A. CONSTANT LAW

lim x→a k f(x) = k (lim x→a f(x)) = k L.

The limit of a constant is that constant provided that limit exists.

B. SUM LAW

lim x→a (f(x) + g(x)) = lim x→a f(x) + lim x→a g(x) = L + M.

The limit of the sums is the sum of the limits provided those limits exist.

C. PRODUCT LAW

lim x→a (f(x) g(x)) = lim x→a f(x) · lim x→a g(x) = L M.

The limit of the products is the product of the limits provided those limits exist.

D. QUOTIENT LAW

lim x→a (f(x) / g(x)) = (lim x→a f(x))/(lim x→a g(x)) = L / M, if M  /=  0.

The limit of the quotients is the quotient of the limits provided those limits exist and the denominator is nonzero.

E. POWER LAW

lim x→a f(x)n = (lim x→a f(x))n = Ln.

F. ROOT LAW

lim x→a n√f(x) = n√lim x→a f(x) = n√L provided if n is even, then f(x) ≥ 0 near a.

G. COMPOSITION LAW

If lim x→a g(x) = M and lim x→M f(x) = f(M), then lim x→a f(g(x)) = f(M).

II. LIMIT DEFINITIONS

A. OFFICIAL LIMIT DEFINITION 

ε is epsilon the lower case of the fifth letter of the Greek alphabet.

δ is delta the lower case of the fourth letter of the Greek alphabet.

lim x→a f(x) = L means

for all ε > 0,

there is δ > 0,

so that if x /= a and x is within δ of a ( δ is measuring how close x is to a )

then f(x) is within ε of L ( ε is measuring how close f(x) is to L )

If no such value of L can be found, then we say that the lim x→a f(x) does not exist (DNE). 

B. ONE-SIDED LIMIT DEFINITION

We say that the limit of f(x) as x goes to a from the left is L,

lim x→a− f(x) = L

if for every ε > 0 there is a δ > 0 so that whenever x < a and

a − δ < x we have |f(x) − L| < ε.

We say that the limit of f(x) as x goes to a from the right is L,

lim x→a+ f(x) = L

if for every ε > 0 there is a δ > 0 so that whenever x > a and

x < a + δ we have |f(x) − L| < ε.

III. USEFUL HASKELL TRIGONOMETRIC FUNCTIONS

Remember Calculus is computed using radians not degrees.

To convert degrees into radians multiply the degrees by pi/180o.

For example, using Haskell 200o converted into radians equals 3.490658503988659 radians as shown using the function below.

f x = x * pi / 180

Some useful built in Haskell Trigonometric functions are as follows:

sin

cos

tan

asin

atan

acos

sinh

tanh

cosh

asinh

atanh

acosh

IV. HASKELL LIMIT EXAMPLES

A. CONSTANT LAW



B. SUM LAW



C. PRODUCT LAW



D. QUOTIENT LAW



E. POWER LAW



F. ROOT LAW



G. COMPOSITION LAW



V. HASKELL LIMIT THEOREMS

A. INTERMEDIATE VALUE THEOREM

If f(x) is a continuous function for all x in the closed interval [a,b] and d is in between f(a) and f(b), then there is a number c in [a,b] such that f(c) = d.

B. SQUEEZE THEOREM

Suppose that g(x) ≤ f(x) ≤ h(x) for all x close to a but not necessarily equal to a. If

lim x→a g(x) = L = lim x→a h(x),

then lim x→a f(x) = L.

VI. CONCLUSION

In this tutorial, you have been introduced to using Haskell to solve integral calculus limit equations.

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