Reverse-mode differentiation is used for optimization, but it introduces references, which break the purity of the underlying programs, making them notoriously harder to optimize. We present a reverse-mode differentiation on a purely functional language with array operations. It is the first one to deliver a provably efficient, purely functional, and denotationally correct reverse-mode differentiation. We show that our transformation is semantically correct and verifies the cheap gradient principle. Inspired by PROPs and compilation to categories, we introduce a novel intermediate representation that we call 'unary form'. Our reverse-mode transformation is factored as a compilation scheme through this intermediate representation. We obtain provably efficient gradients by performing general partial evaluation optimizations after our reverse-mode transformation, as opposed to manually derived ones. For simple first-order programs, the obtained output programs resemble static-single-assignment (SSA) code. We emphasize the modularity of our approach and show how our language can easily be enriched with more optimized primitives, as required for some speed-ups in practice.
翻译:反向模式差异用于优化, 但是它引入了引用, 打破了基础程序的纯度, 令它们更难优化。 我们展示了一种对纯功能语言的反向模式差异, 使用阵列操作。 这是第一个提供一种可辨别效率高、功能纯功能化和分辨正确的反向模式差异的方案。 我们显示, 我们的变换在语义上是正确的, 并验证了低廉的梯度原则。 在PROPs和分类汇编的启发下, 我们引入了一种新型的中间代表, 我们称之为“ 单一形式 ” 。 我们的反向模式变换通过这种中间表达方式将它作为一个编译方案进行计算。 我们通过在我们反向模式变换后实施一般部分评价优化, 而不是手动的衍生方法, 获得了非常简单的一阶程序, 获得的输出程序类似于静式单式任务( SSS) 代码。 我们强调我们的方法的模块化, 并显示我们的语言是如何轻易地用更优化的原始形式来补充我们的语言, 这是实践中某些快速增长的需要 。