Simple question. How can we construct functions like Mathematica does?
For example, let's say that we want to create our own
D function works like:
In:= D[x^2, x] Out= 2 x
where we can put a function in
x and the function will treat this internally in a correct way.
How can we create our
D1 function with the same behavior?
In:= D1[f_, x_] := Limit[(-f[x] + f[x + a])/a, a -> 0] In:= D1[x^2, x] Out= Limit[(-(x^2)[x] + (x^2)[a + x])/a, a -> 0] In:= D1[Function[x, x^2], x] Out= 2 x In:= D1[#^2 &, x] Out= 2 x
As we can see, the second and third example work, but I'd like to create a function that would work like in the first example and like the
How can we do this?