We show how to define forward- and reverse-mode automatic differentiation source-code transformations or on a standard higher-order functional language. The transformations generate purely functional code, and they are principled in the sense that their definition arises from a categorical universal property. We give a semantic proof of correctness of the transformations. In their most elegant formulation, the transformations generate code with linear types. However, we demonstrate how the transformations can be implemented in a standard functional language without sacrificing correctness. To do so, we make use of abstract data types to represent the required linear types, e.g. through the use of a basic module system.
翻译:我们展示了如何定义前向和反向模式自动区分源码转换或标准高阶功能语言。这些转换产生纯粹的功能代码,它们具有原则性,因为其定义产生于绝对的普遍财产。我们用语义来证明这些转换的正确性。在最优雅的表述中,这些转换产生线性类型的代码。然而,我们展示了如何在不牺牲正确性的情况下以标准功能语言实施这些转换。为此,我们利用抽象数据类型来代表所需的线性类型,例如通过使用基本模块系统。