Processing math: 100%

2014-06-29

Implicit mapping

The last post was about what happens when one tries to apply a function to a value that is too small (not wrapped in an applicative functor). This post is about what happens when the value is too big (wrapped in too many functors). Jakub Marian defines (when translated into my notation):
(f g) x=f (g x)f A={f x:xA}I posted the applicative function definition in the last post, but here we only need a regular functor. As far as I understand it, a functor is what comes directly from category theory, and an applicative functor just adds some functions that they nearly always have. There are very few functors that cannot be made into applicative functors.

A functor f provides us with just:
fmap:(ab)f af bFor sets, fmap applies a function to every element of the set (eliminating duplicates afterwards), and for functions, it composes the given function (type (ab)) to the left of the functor's function (type f a, which is ta). I encourage you to see why the types work for the latter example.

So, post done? Pretty much. It's maybe worth going through the example of neg neg 1D, where neg:RR is the negation function and D:(RR)RR is the differentiation function (and the superscript-subscript notation is described in the initial post). Of course, limiting to real numbers is arbitrary; I just needed a number type.

Firstly, we try to apply neg:RR to neg 1:RR. RR doesn't match R, but it does match f R, where f=(a). So, we transform neg neg 1 into fmap neg neg 1, which is negneg 1, the negative reciprocal function. Let's call it negrec:RR.

Next, we try to apply that to D:(RR)RR. D's type certainly doesn't match the expected R, but it does match h (g R), where g=(b) (where b=R) and h=(c) (where c=RR). Note that it doesn't match i R where i=((RR)R) because is not associative (it binds to the right). So, negrec D becomes fmap (fmap negrec) D, or (negrec)D.

That's as far as we can go, so let's apply this function to, say, exp and 0. ((negrec)D) exp 0=((negrec) (D exp)) 0=(negrecexp) 0=negrec (exp0)=negrec 1=neg 1And that tells us that the gradient of the normal to the exponential curve at 0 is negative 1.

No comments:

Post a Comment