4 ms·
This is an interesting approach. Haskell is not a symbolic language, but you take advantage of the abstractness of type parameters in function definitions to th
by sterlind 4y ago
This is an interesting approach. Haskell is not a symbolic language, but you take advantage of the abstractness of type parameters in function definitions to thread your implementation of "D x" through, and pattern match on that.
It's a neat design pattern. I bet it'd work in Julia too.
- xiphias2 4y agoYes, but Julia has both forward and backward differention implemented (backwards it's harder).
- ttesmer 4y agoAs I wrote in the Markdown file, there's also a usable package for Haskell called `ad` on Hackage. It has both forward and backward autodiff and prevents expression swell, among other things. This gist is just for illustration purposes.
- warinukraine 4y ago
- version_five 4y agoFor an example in julia, see Mike Innes tutorial: https://github.com/MikeInnes/diff-zoo https://github.com/MikeInnes/diff-zoo I'm only a beginner in Julia and not and AD expert, but I went through the exercise of porting this to python and found it very enlightening
- bmitc 4y ago> Haskell is not a symbolic language I'm not sure I understand what this means. What is a symbolic language that excludes languages like Haskell, F#, OCaml, etc.?
- klipt 4y agoPerhaps they mean not homoiconic like lisp or forth.
- chowells 4y agoA symbolic language is something like mathematica. Mathematica does evaluation as term rewriting with rules for how to rewrite all sorts of things - and if it can't find matching rules, it leaves the expression in the same symbolic form as the input.
- bmitc 4y agoYou can do that with symbolic expressions in all the languages I listed.
- sterlind 4y agoIn Mathematica, the equivalent of a "function call" would be something like f[x,y]. I can write and run that, and it won't give an error if f, x or y aren't defined. Fundamentally, all atoms in the language are terms of symbols. Expressions are broken down by patterns until they're reduced as far as they can be, then the language happily stops and returns how far it got. It's like Lisp, if everything in Lisp were quoted, and eval consisted of pattern matching and applying substitution rules. As an example, say in Haskell I have foo x y = x + 2/y. Can you write a function that takes any function in, and replaces all + with *? in Mathematica you can: foo[x_,y_] := x + 2/y; foo[x,y] /. l_ + r_ -> l*r. I'm sure you can do this stuff in other languages if you try hard enough. Some kind of reflection in Haskell or F#. In Lisp, grab and quote the definition of foo and apply macro machinery to it. But that's not the tao of those languages, while it is the essence of Mathematica.
- chowells 4y ago> Some kind of reflection in Haskell In Haskell you can only do that kind of manipulation at compile time. At run time, the source code is long gone. And even at compile time, expressions are a very different type than code that can be run. Haskell just isn't anything like a symbolic language. As pointed out way upthread, it provides lots of hooks for programmers to have nice syntax for entry points to symbolic systems - if someone writes one.