Skip to main content
QUICK REVIEW

[Paper Review] Denotational Correctness of Forward-Mode Automatic Differentiation for Iteration and Recursion

Matthijs Vákár|arXiv (Cornell University)|Jul 10, 2020
Numerical Methods and AlgorithmsComputer Science18 references8 citations
TL;DR

This paper presents a denotational correctness proof for forward-mode automatic differentiation (AD) in a functional language with recursion, iteration, and partiality—such as undefined operations, lazy conditionals, and recursive types. Using diffeological spaces and a semantic logical relations framework with sheaf-like relations, it establishes that the AD transformation correctly computes derivatives even in the presence of complex control flow and recursive data structures.

ABSTRACT

We present semantic correctness proofs of forward-mode Automatic Differentiation (AD) for languages with sources of partiality such as partial operations, lazy conditionals on real parameters, iteration, and term and type recursion. We first define an AD macro on a standard call-by-value language with some primitive operations for smooth partial functions and constructs for real conditionals and iteration, as a unique structure preserving macro determined by its action on the primitive operations. We define a semantics for the language in terms of diffeological spaces, where the key idea is to make use of a suitable partiality monad. A semantic logical relations argument, constructed through a subsconing construction over diffeological spaces, yields a correctness proof of the defined AD macro. A key insight is that, to reason about differentiation at sum types, we work with relations which form sheaves. Next, we extend our language with term and type recursion. To model this in our semantics, we introduce a new notion of space, suitable for modeling both recursion and differentiation, by equipping a diffeological space with a compatible $ω$cpo-structure. We demonstrate that our whole development extends to this setting. By making use of a semantic, rather than syntactic, logical relations argument, we circumvent the usual technicalities of logical relations techniques for type recursion.

Motivation & Objective

  • To formally prove the correctness of forward-mode automatic differentiation (AD) in a functional language extended with recursion, iteration, and partial operations.
  • To address the challenge of differentiating programs with partiality—such as undefined functions at kinks (e.g., ReLU) or divergent computations—within a denotational semantics framework.
  • To extend existing semantic correctness results for AD to include term and type recursion, which are essential in real-world functional programming languages.
  • To develop a semantic, rather than syntactic, logical relations argument that avoids technical complications in type recursion while preserving correctness.
  • To provide a mathematically rigorous foundation for AD in systems like PyTorch, Stan, and TensorFlow Eager, which rely on AD with recursion and partial features.

Proposed method

  • Defines a forward-mode AD macro as a structure-preserving transformation on a call-by-value functional language with primitive smooth partial functions, real conditionals, and iteration.
  • Models the language semantics using diffeological spaces equipped with a partiality monad to handle undefined values and partial functions.
  • Constructs a semantic logical relations argument via a subsconing construction over diffeological spaces, where relations form sheaves to reason about differentiation at sum types.
  • Introduces a new class of spaces—ω-diffeological spaces—by equipping diffeological spaces with an ω-cpo structure to model term and type recursion.
  • Lifts the correctness proof to the full language with recursion by showing that bilimits in the category of ω-diffeological spaces preserve the required structure for AD correctness.
  • Uses a codistributive law and reflective subcategory techniques to ensure that the interpretation of recursive types in the semantic model respects the AD transformation.

Experimental results

Research questions

  • RQ1How can forward-mode AD be formally proven correct in the presence of partial functions, such as log at zero or ReLU at zero?
  • RQ2How can recursive data types and recursive functions be modeled in a semantic framework that simultaneously supports differentiation and partiality?
  • RQ3Can a semantic, rather than syntactic, logical relations argument be used to prove correctness of AD in the presence of type recursion?
  • RQ4What mathematical structures are needed to model both differentiation and recursion in a unified semantic framework?
  • RQ5How can the correctness of AD be extended from first-order, non-recursive languages to full functional languages with higher-order functions, recursion, and sum types?

Key findings

  • The paper establishes that the forward-mode AD macro correctly computes derivatives for all programs in the language, including those with partial operations and recursive constructs.
  • The use of diffeological spaces with a partiality monad provides a robust semantic foundation for handling undefined values and kinked functions like ReLU.
  • The construction of logical relations as sheaves enables correct reasoning about differentiation at sum types, which is essential for modeling conditional branching in derivatives.
  • The introduction of ω-diffeological spaces allows the semantics to model both recursion and differentiation, enabling the extension of correctness to recursive types.
  • The correctness result lifts to the full language with term and type recursion, demonstrating that the AD transformation is sound even for algebraic data types like lists and trees of reals.
  • The semantic approach avoids the technical complexities of syntactic logical relations in the presence of recursion, offering a cleaner and more general proof technique.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.