Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
Let 𝑔 :ℝ2 →ℝ be given by a program, and suppose we want 𝜕𝑔/𝜕𝑥1 at a point. Two answers present themselves and both fail.
Symbolic differentiation rewrites the expression 𝑔 into an expression for its derivative. It works for the grammar of arithmetic expressions, and it stops working as soon as the program contains a function-valued subterm: there is no rule for differentiating 𝜆𝑓. 𝑓 (𝑓 𝑥), because the expression to be differentiated is not built from +, ∗, and named smooth constants, and the intermediate object 𝑓 has no derivative until it is instantiated.
Numerical differencing evaluates (𝑔(𝑥 +𝜀𝑒1) −𝑔(𝑥))/𝜀. It applies to any program, and it certifies nothing: for every finite set of tolerances and step sizes there are two smooth functions agreeing on all of them whose derivatives at 𝑥 differ, so agreement of a transformation with a difference quotient at finitely many points is not evidence that the transformation computes a derivative.
What is wanted is a source-to-source transformation, defined by induction on the program including its higher-order subterms, together with a theorem stating what the transformed program denotes. This chapter fixes one source language, defines that transformation, and proves the theorem at first-order input and output types, higher-order subterms being permitted inside. The proof is a logical relation between what the program denotes and what its transform denotes; the interesting clause is at function types, and it is forced, not chosen.
The invariant to be maintained
Before any syntax, fix what the transformed program is supposed to compute.
Let 𝑔 :ℝ𝑛 →ℝ. A function ℎ :(ℝ ×ℝ)𝑛 →ℝ ×ℝ is a tangent representation of 𝑔 when for all smooth 𝑓1,…,𝑓𝑛 :ℝ →ℝ and all 𝑥 ∈ℝ, ℎ(𝑓1(𝑥),𝑓′1(𝑥),…,𝑓𝑛(𝑥),𝑓′𝑛(𝑥))=(𝑔(𝑓1(𝑥),…,𝑓𝑛(𝑥)), (𝑔∘(𝑓1,…,𝑓𝑛))′(𝑥)).
Referenced from 4 locations
Equation 182.1 is a statement about composition, not about a single point, and that is what makes it usable as an induction hypothesis: it says that ℎ transports first-order Taylor data through 𝑔. Instantiating it recovers the familiar quantities.
Take 𝑛 =2, fix 𝑎 ∈ℝ2, and let 𝑓1(𝑥):=𝑥, 𝑓2(𝑥):=𝑎2, evaluated at 𝑥 =𝑎1. Then 𝑓′1 =1 and 𝑓′2 =0, and equation 182.1 reads ℎ(𝑎1,1,𝑎2,0)=(𝑔(𝑎), 𝜕𝑔𝜕𝑥1(𝑎)). Choosing 𝑓′1 =0, 𝑓′2 =1 gives the other partial derivative, and a general pair of tangents gives the directional derivative. So a single ℎ satisfying equation 182.1 contains all first-order derivative information about 𝑔, and one evaluation of ℎ yields one directional derivative at the cost of one evaluation of 𝑔 up to a constant factor.
Referenced from 5 locations
The source language
Fix for each 𝑛 ≥0 a set Op𝑛 of 𝑛-ary operation symbols, containing a symbol 𝑐―― for each 𝑐 ∈ℝ in Op0 and containing +, ∗ ∈Op2. Types and terms are 𝜏,𝜎 ::= 𝗋𝖾𝖺𝗅 ∣ (𝜏1∗⋯∗𝜏𝑛) ∣ 𝜏→𝜎, 𝑡,𝑠 ::= 𝑥 ∣ op(𝑡1,…,𝑡𝑛) ∣ ⟨𝑡1,…,𝑡𝑛⟩∣ 𝖼𝖺𝗌𝖾 𝑡 𝗈𝖿 ⟨𝑥1,…,𝑥𝑛⟩→𝑠 ∣ 𝜆𝑥:𝜏.𝑡 ∣ 𝑡𝑠. The typing rules are the expected ones: a variable has its declared type; op ∈Op𝑛 applied to 𝑛 terms of type 𝗋𝖾𝖺𝗅 has type 𝗋𝖾𝖺𝗅; a tuple of terms of types 𝜏𝑖 has the product type; 𝖼𝖺𝗌𝖾 eliminates a product by binding its components; abstraction and application are as in chapter 2. We write Γ ⊢𝑡 :𝜏 and use 𝗅𝖾𝗍 𝑥 =𝑡 𝗂𝗇 𝑠 for (𝜆𝑥. 𝑠) 𝑡.
Referenced from 5 locations
Assume given for each op ∈Op𝑛 a smooth function [[op]] :ℝ𝑛 →ℝ, with [[𝑐――]] =𝑐, [[ +]] addition and [[ ∗]] multiplication. Interpret [[𝗋𝖾𝖺𝗅]]:=ℝ, products as products of sets, and [[𝜏 →𝜎]] as the set of all functions [[𝜏]] →[[𝜎]]. A context Γ =𝑥1 :𝜏1,…,𝑥𝑚 :𝜏𝑚 denotes the product of the [[𝜏𝑖]], and a derivation of Γ ⊢𝑡 :𝜏 denotes a function [[𝑡]] :[[Γ]] →[[𝜏]] by the usual clauses: variables project, 𝗈𝗉 applies [[op]], tuples pair, 𝖼𝖺𝗌𝖾 substitutes the components, abstraction curries, and application evaluates.
Referenced from 4 locations
Interpreting 𝜏 →𝜎 by all functions is deliberately crude: it makes [[𝑡]] defined for every term, and it makes no claim of smoothness at function types, where no claim is yet available. The correctness theorem below never mentions [[𝜏 →𝜎]] except through the logical relation.
The tangent macro
On types, D(𝗋𝖾𝖺𝗅):=(𝗋𝖾𝖺𝗅∗𝗋𝖾𝖺𝗅),D(𝜏→𝜎):=D𝜏→D𝜎,D(𝜏1∗⋯∗𝜏𝑛):=(D𝜏1∗⋯∗D𝜏𝑛). On terms, D is the identity on variables and commutes with every constructor, D(𝜆𝑥:𝜏.𝑡):=𝜆𝑥:D𝜏.D𝑡,D(𝑡𝑠):=(D𝑡)(D𝑠), and similarly for tuples and 𝖼𝖺𝗌𝖾, except at operations: D(op(𝑡1,…,𝑡𝑛)):= 𝖼𝖺𝗌𝖾 D𝑡1 𝗈𝖿 ⟨𝑥1,𝑥′1⟩→⋯𝖼𝖺𝗌𝖾 D𝑡𝑛 𝗈𝖿 ⟨𝑥𝑛,𝑥′𝑛⟩→⟨op(⃗𝑥), ∑𝑛𝑖=1𝜕𝑖op(⃗𝑥)∗𝑥′𝑖⟩, where ⃗𝑥 abbreviates 𝑥1,…,𝑥𝑛 and 𝜕𝑖op is a chosen term of the language, with free variables among 𝑥1,…,𝑥𝑛, such that [[𝜕𝑖op]] =𝜕[[op]]/𝜕𝑥𝑖. For a context Γ, write DΓ for the context with each type replaced by its image.
Referenced from 10 locations
If Γ ⊢𝑡 :𝜏 then DΓ ⊢D𝑡 :D𝜏.
Referenced from 3 locations
Proof of Lemma 182.7 — The macro preserves typing
Proof. Induction on the typing derivation. Every clause but the operation clause replaces each type by its image and leaves the rule shape unchanged, so the same rule applies. For op(𝑡1,…,𝑡𝑛), the induction hypothesis gives DΓ ⊢D𝑡𝑖 :(𝗋𝖾𝖺𝗅 ∗𝗋𝖾𝖺𝗅); each 𝖼𝖺𝗌𝖾 then binds 𝑥𝑖,𝑥′𝑖 at type 𝗋𝖾𝖺𝗅, the terms op(𝑥1,…,𝑥𝑛) and 𝜕𝑖op(𝑥1,…,𝑥𝑛) have type 𝗋𝖾𝖺𝗅 by the operation rule, and the displayed pair has type (𝗋𝖾𝖺𝗅 ∗𝗋𝖾𝖺𝗅) =D(𝗋𝖾𝖺𝗅). ◻
Let 𝑡:=𝑥1 ∗𝑥2 +𝑥1 with 𝑥1,𝑥2 :𝗋𝖾𝖺𝗅. Writing ⟨𝑎,𝑎′⟩ for the pair bound to 𝑥1 and ⟨𝑏,𝑏′⟩ for the pair bound to 𝑥2, the macro gives, after the 𝖼𝖺𝗌𝖾 bindings are performed, D𝑡=⟨𝑎∗𝑏+𝑎, (𝑏∗𝑎′+𝑎∗𝑏′)+𝑎′⟩, using 𝜕1 ∗(𝑥1,𝑥2) =𝑥2, 𝜕2 ∗(𝑥1,𝑥2) =𝑥1, and 𝜕1 + =𝜕2 + =1――. Evaluating at 𝑎′ =1,𝑏′ =0 gives (𝑎𝑏 +𝑎, 𝑏 +1), which is the value together with 𝜕(𝑥1𝑥2 +𝑥1)/𝜕𝑥1, as example 182.2 predicts.
Referenced from 2 locations
Let 𝑡:=(𝜆𝑓:𝗋𝖾𝖺𝗅→𝗋𝖾𝖺𝗅. 𝑓(𝑓𝑥))(𝜆𝑦:𝗋𝖾𝖺𝗅. 𝑦∗𝑦), so 𝑥 :𝗋𝖾𝖺𝗅 ⊢𝑡 :𝗋𝖾𝖺𝗅 and [[𝑡]](𝑥) =𝑥4. The macro does not differentiate the higher-order subterm symbolically; it applies itself structurally, giving D𝑡=(𝜆𝑓:D(𝗋𝖾𝖺𝗅→𝗋𝖾𝖺𝗅). 𝑓(𝑓𝑥))(𝜆𝑦:(𝗋𝖾𝖺𝗅∗𝗋𝖾𝖺𝗅). 𝑦∗D𝑦), where 𝑦 ∗D𝑦 abbreviates the operation clause at ∗. Evaluating D𝑡 at ⟨𝑎,1⟩: the inner function sends ⟨𝑢,𝑢′⟩ to ⟨𝑢2,2𝑢𝑢′⟩, so two applications give ⟨𝑎2,2𝑎⟩ and then ⟨𝑎4,2𝑎2 ⋅2𝑎⟩ =⟨𝑎4,4𝑎3⟩. The derivative of 𝑥4 is obtained without any rule for differentiating 𝜆𝑓. 𝑓(𝑓 𝑥), which is the point: D is defined on all terms, including those a symbolic differentiator has no rule for.
Referenced from 4 locations
★☆☆ Apply D to 𝑡:=𝜍(𝑥1 ∗𝑥2) for a unary operation 𝜍 with 𝜕1𝜍 =𝜍′, and evaluate the result at ⟨𝑎,1⟩,⟨𝑏,0⟩. Check the answer against the chain rule.
Referenced from 2 locations
★★☆ Show that D(𝗅𝖾𝗍 𝑥 =𝑡 𝗂𝗇 𝑠) and 𝗅𝖾𝗍 𝑥 =D𝑡 𝗂𝗇 D𝑠 are the same term, and explain why the analogous statement for a symbolic differentiator that substitutes 𝑡 for 𝑥 before differentiating changes the number of operations executed.
Referenced from 2 locations
Correctness
The macro is defined by structural recursion, so its correctness proof must be by structural induction; and the statement to be proved cannot be equation 182.1 itself, because that statement mentions only 𝗋𝖾𝖺𝗅 and the induction passes through function types. The standard repair is to define, for every type, a relation between what a term denotes and what its transform denotes, arranged so that the function-type clause is preserved by application. Here the relation is between smooth curves, since equation 182.1 is itself a statement about curves.
For each type 𝜏 define 𝑆𝜏 ⊆(ℝ →[[𝜏]]) ×(ℝ →[[D𝜏]]) by induction on 𝜏: 𝑆𝗋𝖾𝖺𝗅:={(𝑓, 𝑥↦(𝑓(𝑥),𝑓′(𝑥))) : 𝑓:ℝ→ℝ smooth},𝑆(𝜏1∗⋯∗𝜏𝑛):={((𝑓1,…,𝑓𝑛),(𝑔1,…,𝑔𝑛)) : (𝑓𝑖,𝑔𝑖)∈𝑆𝜏𝑖 for each 𝑖},𝑆𝜏→𝜎:={(𝐹,𝐺) : for all (𝑎,𝑏)∈𝑆𝜏,(𝑥↦𝐹(𝑥)(𝑎(𝑥)), 𝑥↦𝐺(𝑥)(𝑏(𝑥)))∈𝑆𝜎}. For a context Γ =𝑥1 :𝜏1,…,𝑥𝑚 :𝜏𝑚, write (𝛾,𝛿) ∈𝑆Γ when the 𝑖-th components are related by 𝑆𝜏𝑖 for each 𝑖.
Referenced from 8 locations
The clause at 𝜏 →𝜎 is the only one with a choice in it, and there is no choice: the induction step for application must turn related functions and related arguments into related results, and the displayed clause is exactly that requirement read as a definition. Note also what the clause does not say: it does not assign a derivative to a higher-order value. It relates a curve of functions to a curve of functions, and two different curves in [[D(𝜏 →𝜎)]] may be related to the same curve in [[𝜏 →𝜎]].
Let Γ ⊢𝑡 :𝜏 and let (𝛾,𝛿) ∈𝑆Γ. Then (𝑥↦[[𝑡]](𝛾(𝑥)), 𝑥↦[[D𝑡]](𝛿(𝑥)))∈𝑆𝜏.
Referenced from 9 locations
Proof of Lemma 182.11 — Fundamental lemma
Proof. Induction on the derivation of Γ ⊢𝑡 :𝜏.
Variable. Both sides are the corresponding components of 𝛾 and 𝛿, related by hypothesis.
Abstraction. Let 𝑡 =𝜆𝑥 :𝜎. 𝑠 with Γ,𝑥 :𝜎 ⊢𝑠 :𝜌. Let (𝑎,𝑏) ∈𝑆𝜎. Then ((𝛾,𝑎),(𝛿,𝑏)) ∈𝑆Γ,𝑥:𝜎, so the induction hypothesis gives that 𝑥 ↦[[𝑠]](𝛾(𝑥),𝑎(𝑥)) and 𝑥 ↦[[D𝑠]](𝛿(𝑥),𝑏(𝑥)) are related by 𝑆𝜌. These are exactly the two curves required by the clause at 𝜎 →𝜌 applied to the curves 𝑥 ↦[[𝑡]](𝛾(𝑥)) and 𝑥 ↦[[D𝑡]](𝛿(𝑥)).
Application. Immediate from the clause at 𝜎 →𝜌 and the two induction hypotheses.
Tuples and 𝖼𝖺𝗌𝖾. Componentwise from the product clause; for 𝖼𝖺𝗌𝖾, the induction hypothesis for the scrutinee gives related component curves, which extend the environments as in the abstraction case.
Operations. Let 𝑡 =op(𝑡1,…,𝑡𝑛). By the induction hypothesis, for each 𝑖 there is a smooth 𝑓𝑖 :ℝ →ℝ with [[𝑡𝑖]](𝛾(𝑥)) =𝑓𝑖(𝑥) and [[D𝑡𝑖]](𝛿(𝑥)) =(𝑓𝑖(𝑥),𝑓′𝑖(𝑥)). Reading definition 182.6 at these values, the first component of [[D𝑡]](𝛿(𝑥)) is [[op]](𝑓1(𝑥),…,𝑓𝑛(𝑥)), which is [[𝑡]](𝛾(𝑥)), and the second is 𝑛∑𝑖=1𝜕[[op]]𝜕𝑥𝑖(𝑓1(𝑥),…,𝑓𝑛(𝑥))⋅𝑓′𝑖(𝑥)𝑐ℎ𝑎𝑖𝑛𝑟𝑢𝑙𝑒=([[op]]∘(𝑓1,…,𝑓𝑛))′(𝑥). The composite [[op]] ∘(𝑓1,…,𝑓𝑛) is smooth, being a composite of smooth functions, so the pair lies in 𝑆𝗋𝖾𝖺𝗅. ◻
Let Γ ⊢𝑡 :𝗋𝖾𝖺𝗅 where every variable of Γ =𝑥1 :𝗋𝖾𝖺𝗅,…,𝑥𝑛 :𝗋𝖾𝖺𝗅 has type 𝗋𝖾𝖺𝗅. Let ⃗𝑓:=(𝑓1,…,𝑓𝑛) be an 𝑛-tuple of smooth functions ℝ →ℝ and write ⃗𝑓(𝑥) for the tuple of their values at 𝑥. Then [[𝑡]] ∘⃗𝑓 is smooth and [[D𝑡]](𝑓1(𝑥),𝑓′1(𝑥),…,𝑓𝑛(𝑥),𝑓′𝑛(𝑥))=([[𝑡]](⃗𝑓(𝑥)), ([[𝑡]]∘⃗𝑓)′(𝑥)). That is, [[D𝑡]] is a tangent representation of [[𝑡]] in the sense of definition 182.1. In particular [[D𝑡]](𝑎1,1,𝑎2,0,…,𝑎𝑛,0) =([[𝑡]](𝑎), 𝜕[[𝑡]]/𝜕𝑥1(𝑎)) whenever [[𝑡]] is differentiable in its first argument at 𝑎.
Referenced from 14 locations
Proof of Theorem 182.12 — Correctness at a first-order interface
Proof. Consider the two curves 𝛾(𝑥):=⃗𝑓(𝑥),𝛿(𝑥):=(𝑓1(𝑥),𝑓′1(𝑥),…,𝑓𝑛(𝑥),𝑓′𝑛(𝑥)). They satisfy (𝛾,𝛿) ∈𝑆Γ by definition 182.10. Apply lemma 182.11 and read off the clause 𝑆𝗋𝖾𝖺𝗅: the first curve is smooth, and the second is the pair consisting of it and its derivative. The final sentence is example 182.2, taking 𝑓1 =id and every other 𝑓𝑖 constant. ◻
Let 𝑘,𝑅 ≥1 and let D(𝑘,𝑅) be the macro of definition 182.6 with D(𝑘,𝑅)(𝗋𝖾𝖺𝗅) the type of tuples of (𝑅+𝑘𝑘) reals and with the operation clause given by the multivariate Faà di Bruno formula.
For every 𝑡 with 𝑥1 :𝗋𝖾𝖺𝗅,…,𝑥𝑛 :𝗋𝖾𝖺𝗅 ⊢𝑡 :𝗋𝖾𝖺𝗅, the function [[D(𝑘,𝑅)𝑡]] is the (𝑘,𝑅)-Taylor representation of [[𝑡]]: it transports all partial derivatives of order at most 𝑅 of any 𝑛-tuple of smooth maps ℝ𝑘 →ℝ through [[𝑡]].
For every first-order type 𝜏, every first-order context Γ, and every Γ ⊢𝑡 :𝜏, the translation D(𝑘,𝑅) coincides with the (𝑘,𝑅)-jet bundle functor, modulo canonical isomorphisms [[D(𝑘,𝑅)𝜏]] ≅𝐷(𝑘,𝑅)[[𝜏]].
Referenced from 4 locations
Clause (i) is Theorem 4.3 and clause (ii) is Theorem 6.6 of Huot, Staton, and Vákár, Higher Order Automatic Differentiation of Higher Order Functions, arXiv:2101.06757. Their proofs interpret the language in diffeological spaces — sets equipped with a family of plots ℝ𝑘 →𝑋 closed under smooth reparametrization — and run the argument of lemma 182.11 inside a category glued along plots; clause (ii) additionally uses that smooth maps out of a connected ℝ𝑘 into a disjoint union of manifolds factor through one summand. Theorem 182.12 is the case 𝑘 =𝑅 =1 with first-order interface, proved above over ordinary sets because at that instance the relation of definition 182.10 is already reflexive on the curves it needs. What is imported is exactly (i) and (ii); nothing is imported about recursion, partiality, or nonsmooth primitives, which those authors exclude, and nothing about implementation cost.
Perturbation confusion
Implementations of forward differentiation usually do not implement definition 182.6. They implement a run-time operator D on closures, defined by D𝑓𝑥:=𝗍𝗀(𝑓(𝑥+1𝜖)), where 𝑥 +1𝜖 builds a dual number and 𝗍𝗀 extracts its tangent component. The two settings differ, and the difference is not cosmetic.
Evaluate D(𝜆𝑥. 𝑥 ∗D(𝜆𝑦. 𝑥 +𝑦) 1)1. Mathematically the inner derivative is 1 for every 𝑥, so the function being differentiated is 𝑥 ↦𝑥 and the answer is 1. With a single 𝜖, the outer call binds 𝑥:=1 +1𝜖, the inner call binds 𝑦:=1 +1𝜖, and the inner body is (1 +1𝜖) +(1 +1𝜖) =2 +2𝜖, whose tangent is 2. The outer body is then (1 +1𝜖) ∗2 =2 +2𝜖, whose tangent is 2. The answer is wrong by a factor of two, and the cause is that one symbol 𝜖 was used for two different derivative calculations.
Referenced from 5 locations
The repair is to allocate a fresh tag at each invocation of D and to let 𝗍𝗀𝜖1 pass through dual numbers tagged 𝜖2 ≠𝜖1. That repairs example 182.15 and every first-order nesting. It is not sufficient in general.
Define the offset operator 𝑠 𝑢 𝑓 𝑥:=𝑓(𝑥 +𝑢), of type ℝ →(ℝ →ℝ) →ℝ →ℝ. Then for all 𝑓 and 𝑦, D𝑠0𝑓𝑦=𝜕𝜕𝑢[𝑓(𝑦+𝑢)]𝑢=0=𝑓′(𝑦)=D𝑓𝑦, so ̂D:=D 𝑠 0 ought to equal D. Manzyuk, Pearlmutter, Radul, Rush, and Siskind [MPR^+19] exhibit ℎ and 𝑦 for which ̂D(̂Dℎ) 𝑦 differs from D(D ℎ) 𝑦 under the fresh-tag discipline extended to function-valued results by post-composition, 𝗍𝗀𝜖 ¯𝑔:=𝗍𝗀𝜖 ∘¯𝑔. The cause is that D 𝑠 0 returns a function, so the tag allocated by the outer invocation is captured in a closure and is later reused by an invocation that should have received a distinct tag. Their paper analyses the failure and proposes two repairs, one delaying tag creation by eta expansion and one wrapping the outputs of derivative operators.
Referenced from 3 locations
★★☆ Compute D(D𝑡) for 𝑡:=𝑥 ∗𝑥 and evaluate it at the value that example 182.2 prescribes for a second derivative. Check the result against 𝜕2(𝑥2)/𝜕𝑥2 =2, and identify which component of the four-fold nested pair carries it.
Referenced from 2 locations
★★☆ Redo example 182.15 with distinct tags 𝜖1 for the outer invocation and 𝜖2 for the inner one, using the rule 𝗍𝗀𝜖1(𝑎 +𝑏𝜖2) =(𝗍𝗀𝜖1𝑎) +(𝗍𝗀𝜖1𝑏)𝜖2 for 𝜖1 ≠𝜖2, and verify that the answer is 1. Then state precisely which step of your calculation would fail if the inner invocation reused 𝜖1.
Referenced from 2 locations
Comparisons
Syntactic differentiation. Chapter 181 differentiates a term without any notion of smooth function: its 𝜕𝑠𝜕𝑥 ⋅𝑢 places one linear copy of 𝑢 at one occurrence of 𝑥 and sums. The comparison is exact at one point and misleading elsewhere. Both operations satisfy a product rule and a chain rule, and both are defined by structural recursion. But the resource derivative is about use counting and its correctness criteria are confluence and the Taylor identity of that chapter, while D is about numerical tangents and its correctness criterion is theorem 182.12. No theorem transfers in either direction.
Coherent differentiation. Ehrhard’s coherent differentiation develops a summability structure in which only certain pairs of terms may be added, so that differentiation makes sense without the unrestricted sums of chapter 181. It separates the two settings: the present chapter never adds two program values, because definition 182.6 produces pairs rather than sums, and the addition that appears in the operation clause is the addition of the object language at type 𝗋𝖾𝖺𝗅.
Implementation comparisons. Typed array languages with index sets, such as Dex, implement forward mode with a type discipline that tracks which index sets a tangent belongs to. That design is a comparison only: no array language theorem is imported here, and theorem 182.12 says nothing about arrays. Elliott’s compositional derivation, the survey of Baydin, Pearlmutter, Radul, and Siskind [BPRS18], and the matrix calculus course of Edelman and Johnson [EJ23] supply the dual-number, computation-graph, and finite-difference prelude that section 182.1 compresses into one invariant.
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 182.5, then exercise 182.6; the implementation project exercise 182.8 may be attempted at any time.
★★☆ Suppose the clause 𝑆𝜏→𝜎 of definition 182.10 were replaced by “𝐹 =𝐺 pointwise after erasing tangent components”. Show that lemma 182.11 then fails, by exhibiting a term whose application case cannot be discharged. Then show that the displayed clause is the weakest one that discharges the application case.
Referenced from 3 locations
★★★ Add to definition 182.4 a conditional on reals, written 𝗂𝖿 𝑡 <0 𝗍𝗁𝖾𝗇 𝑠1 𝖾𝗅𝗌𝖾 𝑠2, with the evident denotation, and extend D by applying itself to both branches. Exhibit a closed term of type 𝗋𝖾𝖺𝗅 →𝗋𝖾𝖺𝗅 for which theorem 182.12 becomes false, and identify the step of the proof of lemma 182.11 that breaks. Then state a restriction on the guard under which the proof goes through again, and prove the restricted statement.
Referenced from 3 locations
★★☆ Prove that for first-order 𝜏 and 𝜎 the relation 𝑆𝜏→𝜎 determines its second component uniquely: if (𝐹,𝐺) and (𝐹,𝐺′) are both in 𝑆𝗋𝖾𝖺𝗅→𝗋𝖾𝖺𝗅 then 𝐺 =𝐺′ on the curves that occur. Then exhibit two distinct transforms of one term of type (𝗋𝖾𝖺𝗅 →𝗋𝖾𝖺𝗅) →𝗋𝖾𝖺𝗅 that are both related to it, showing that uniqueness fails at second order.
Referenced from 2 locations
★★★ Practical project.forward-tangent-macro Implement in Agda or Kappa the language of definition 182.4, its evaluator, and the macro D of definition 182.6. Represent terms with typed de Bruijn indices so that lemma 182.7 is enforced by construction, and provide the operations 𝑐――, +, ∗,𝜍 with their derivative terms.
The invariant to maintain is the one used in the proof of lemma 182.11: at every operation node the transformed program computes the pair whose components are op(⃗𝑥) and ∑𝑖𝜕𝑖op(⃗𝑥) ∗𝑥′𝑖, and no other node inspects a tangent component. The concrete result is a function taking a term 𝑡 with 𝑛 real inputs, a point 𝑎, and a seed vector, and returning the pair produced by evaluating D𝑡.
Acceptance test. For 𝑡 =𝑥1 ∗𝑥2 +𝑥1 at 𝑎 =(3,5) with seeds (1,0) and (0,1), the tool returns (18,6) and (18,3); for the higher-order term of example 182.9 at 𝑎 =2 with seed 1 it returns (16,32); for the twice-transformed term D(D(𝑥 ∗𝑥)) the second-order component is 2 at every point; and the term of example 182.15, written in the frozen language by applying D twice rather than by a run-time operator, returns 1 rather than the 2 of the confused evaluation. A mutation that drops the summation in the operation clause, keeping only the 𝑖 =1 summand, must fail the first test on the seed (0,1).
The program evaluates finitely many closed terms at finitely many points. It illustrates theorem 182.12 and does not prove it; in particular agreement at the tested points is not evidence about any other point, which is the content of remark 182.3.
Referenced from 3 locations
Bibliographic notes
The source language, the macro, and both correctness theorems are those of Huot, Staton, and Vákár, Higher Order Automatic Differentiation of Higher Order Functions, arXiv:2101.06757, whose Theorems 4.3 and 6.6 are imported as theorem 182.14; definition 182.1 is their equation (2.1) and definition 182.10 is the case 𝑘 =𝑅 =1 of their logical relation. The observation that the argument can be run over ordinary sets for a simple language, without the diffeological axioms, is due to Barthe and coauthors and is recorded in that paper; the proof of lemma 182.11 above takes that route, which is why no diffeological space appears in this chapter’s own theorem. Correctness for typed automatic differentiation in the presence of partial features is treated by Nunes and Vákár under explicit source-language restrictions; none of those extensions is claimed here.
The perturbation-confusion examples of section 182.5 are from Manzyuk, Pearlmutter, Radul, Rush, and Siskind [MPR^+19], whose analysis of the offset operator is reproduced in outline in example 182.16; the one-tag example goes back to Siskind and Pearlmutter. That paper owns no theorem in this chapter: it is used to delimit theorem 182.12, as remark 182.17 states. Blondel and Roulet’s book-length treatment supplies the one-feature-at-a-time example ladder and the modern terminology; the survey [BPRS18] and the course notes [EJ23] supply the numerical background.