We introduce Combinatory Homomorphic Automatic Differentiation (CHAD), a principled, pure, provably correct define-then-run method for performing forward and reverse mode automatic differentiation (AD) on programming languages with expressive features. It implements AD as a compositional, type-respecting source-code transformation that generates purely functional code. This code transformation is principled in the sense that it is the unique homomorphic (structure preserving) extension to expressive languages of Elliott's well-known and unambiguous definitions of AD for a first-order functional language. Correctness of the method follows by a (compositional) logical relations argument that shows that the semantics of the syntactic derivative is the usual calculus derivative of the semantics of the original program. In their most elegant formulation, the transformations generate code with linear types. However, the code transformations can be implemented in a standard functional language lacking linear types: while the correctness proof requires tracking of linearity, the actual transformations do not. In fact, even in a standard functional language, we can get all of the type-safety that linear types give us: we can implement all linear types used to type the transformations as abstract types, by using a basic module system. In this paper, we detail the method when applied to a simple higher-order language for manipulating statically sized arrays. However, we explain how the methodology applies, more generally, to functional languages with other expressive features. Finally, we discuss how the scope of CHAD extends beyond applications in AD to other dynamic program analyses that accumulate data in a commutative monoid.
翻译:我们引入混合同质自动差异( CHAD), 这是一种有原则的、 纯的、 准确的、 定义和运行的正确的方法, 用于在有表达功能的编程语言上执行前向和反向模式自动区别( AD) 。 它将AD 作为一种组成性、 尊重类型源代码的转换, 生成纯功能代码。 这种代码转换具有原则性, 因为它是埃利奥特( Elliott) 的著名、 毫不含糊的表达语言的表达式扩展( CHAD ) 。 方法的正确性, 遵循一种( 组合性) 逻辑关系参数, 显示超前向和反向模式的自动区分( ADAD) 。 在最优的配制中, 代码转换产生线性类型的代码。 然而, 代码转换可以在缺乏线性类型的标准功能语言中实施: 虽然正确性证据需要跟踪直线性, 实际变不。 事实上, 即使在一种标准的功能性语言中, 我们可以得到直线性类型的所有类型安全性分析, 使得直线性语言类型分析 能够让我们最终使用一种更高的数据转换方法。 然而, 我们可以使用所有直为直系的系统, 。 使用直系式的系统, 使用所有直系式 。