-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code to treat differentiate as a first class higher order function #33
base: master
Are you sure you want to change the base?
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. |
@@ -9,14 +9,38 @@ export differentiate | |||
# | |||
################################################################# | |||
|
|||
differentiate(ex::SymbolicVariable, wrt::SymbolicVariable) = (ex == wrt) ? 1 : 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this?
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