code to treat differentiate as a first class higher order function#33
code to treat differentiate as a first class higher order function#33Eskatrem wants to merge 2 commits intoJuliaMath:masterfrom
Conversation
…another function, for example: @define myFunction x x*x; myDerivative = @makeDerivative(myFunction, x)
|
I think this needs some revision. (1) I don't want to introduce a global variable to get this functionality. Why does anything need to be cached here? (2) It's not conventional in Julia to introduce a type with untyped fields. Please specify which types you have in mind. |
|
This code also doesn't pass tests. |
|
What's the point of coming up with a strange new syntax for defining functions? The source for any function is accessible via |
|
With |
|
Supplying types is unavoidable because of multiple dispatch. I agree that the output of |
|
Sorry, I didn't realize my code was that messy. I'll address the other issues mentioned by @johnmyleswhite and @ivarne, but I was trying to play with I get in the REPL: And writing the function straight in the REPL returns a similar result. Not sure if that matters, but the version of Julia I am running is julia version 0.2.0-rc4+16. |
|
You need to provide a tuple corresponding to the input types, e.g., |
I added a macro @define to store the code of a function when creating it, and another one @makeDerivative to create functions that are derivatives. It becomes possible to do:
julia> @define myFunction x cos(x*x)
(anonymous function)
julia> myDer = @makeDerivative myFunction x
(anonymous function)
julia> myDer(sqrt(pi))
-2.0083812473182306e-15
julia> myDer2 = @makeDerivative((x_x_sin(x)),x)
(anonymous function)
julia> myDer2(pi)
-9.869604401089358