Search code examples
language-agnosticdifferentiationautomatic-differentiation

What is differentiable programming?


Native support for differential programming has been added to Swift for the Swift for Tensorflow project. Julia has similar with Zygote.

What exactly is differentiable programming?

  • what does it enable? Wikipedia says

    the programs can be differentiated throughout

    but what does that mean?

  • how would one use it (e.g. a simple example)?

  • and how does it relate to automatic differentiation (the two seem conflated a lot of the time)?


Solution

  • I like to think about this question in terms of user-facing features (differentiable programming) vs implementation details (automatic differentiation).

    From a user's perspective:

    • "Differentiable programming" is APIs for differentiation. An example is a def gradient(f) higher-order function for computing the gradient of f. These APIs may be first-class language features, or implemented in and provided by libraries.

    • "Automatic differentiation" is an implementation detail for automatically computing derivative functions. There are many techniques (e.g. source code transformation, operator overloading) and multiple modes (e.g. forward-mode, reverse-mode).

    Explained in code:

    def f(x):
      return x * x * x
    
    ∇f = gradient(f)
    print(∇f(4)) # 48.0
    
    # Using the `gradient` API:
    # ↳ differentiable programming.
    
    # How `gradient` works to compute the gradient of `f`:
    # ↳ automatic differentiation.