On Correctness of Automatic Differentiation for Non-Differentiable Functions

Wonyeol Lee, Hangyeol Yu, Xavier Rival, Hongseok Yang

Introduction

Automatic differentiation or autodiff is one of the key technologies behind the dramatic progress of deep learning in recent years . It refers to the idea of developing and using a generic tool that can differentiate any function expressed as a program in a general-purpose programming language . Effective autodiff systems have been developed for popular programming languages . They have enabled the development of sophisticated models and algorithms in machine learning that, in particular, involve deep neural networks .

This paper is concerned with one seeming contradiction of these autodiff systems: the systems have originally been developed to compute derivatives of differentiable functions, but in practice, they are commonly applied to functions with non-differentiabilities. For instance, neural networks using ReLU define non-differentiable functions in general, but the derivatives of losses involving those functions are computed using autodiff systems in practice. This status quo raises a natural question: are autodiff systems correct in any formal sense when applied to such non-differentiable functions?

A common reaction to the question is: non-differentiabilities arising in deep learning (e.g., from ReLU) do not cause any issues because they occur rarely (i.e., they form a Lebesgue-measure-zero set). In the paper, we first show that this reaction needs to be carefully re-examined at least. Using counterexamples, we point out flaws in three often-used arguments derived from this reaction. We then present our answer. It is also positive, but based on a class of functions that satisfy a condition called piecewise analyticity under analytic partition (in short, PAP). These PAP functions include nearly all (possibly non-differentiable) functions in deep learning nowadays. For these PAP functions, we propose a new type of derivatives, called intensional derivatives, and prove that these derivatives always exist and coincide with standard derivatives for almost all inputs. These intensional derivatives behave almost as well as, and sometimes even better than, usual derivatives for differentiable functions. For instance, they always satisfy a chain rule even if functions are non-differentiable. Using these properties of intensional derivatives, we show that the intensional derivatives are what most autodiff systems compute or try to compute essentially. In this way, we formally establish the correctness of autodiff systems that compute derivatives of non-differentiable functions.

Challenges

As mentioned in the introduction, practitioners frequently apply autodiff systems to functions with non-differentiabilities, and justify these out-of-scope use cases with plausible yet heuristic arguments. In this section, we analyse these arguments. We go through three claims that are often used in the arguments implicitly, and show that although looking innocent at the outset, the claims have serious flaws; they are wrong, and we provide counterexamples.

Recall a notion of correctness for an autodiff system covering non-differentiable functions :

The definition permits a non-differentiable function as an input to an autodiff system, as long as its non-differentiability occurs rarely (i.e., at a measure-zero subset of the input domain). For such a function, it may be impossible to compute the correct derivative for all inputs, simply because the derivative does not exist for inputs where the function is non-differentiable. Thus, the definition just requires that the system should compute the correct derivative for most inputs instead (i.e., for a subset of the input domain whose complement inside the domain is contained in a measure-zero set).

Proving the correctness of an autodiff system is surprisingly difficult. Nearly every autodiff system is based on a chain rule for computing the derivative of function composition, but when the component functions are non-differentiable, designing a correct version of the rule is challenging. To help the reader see this challenge, we analyse three plausible yet flawed claims about the derivative of function composition, which are sometimes used implicitly in heuristic justifications of autodiff systems.

If ff and gg are differentiable almost everywhere and continuous, then g∘fg\circ f should be differentiable almost everywhere.

A rationale for the claim goes as follows. In order for g∘fg\circ f to be non-differentiable at x0x_{0}, the function ff has to be non-differentiable at x0x_{0}, or it should map x0x_{0} to a non-differentiable input to gg and be able to vary enough in a neighbourhood of x0x_{0}. The claim says that such an x0x_{0} is rare (from the perspective of measure). Of course, the first case that ff is non-differentiable at x0x_{0} occurs rarely by assumption. The second case seems to happen rarely as well, because the non-differentiable inputs to gg are rare and ff is continuous: because of continuity, if ff maps many x0x_{0}’s (i.e., all the x0x_{0} in some non-measure-zero set) to those rare non-differentiable inputs of gg, it should behave as a constant function in the neighbourhoods of most of those x0x_{0}’s.

The rationale has a flaw, and the claim is false. The inputs x0x_{0} falling into the second case are not necessarily rare. Although ff is continuous, it is possible that ff maps many x0x_{0}’s to some of those rare non-differentiable inputs of gg without acting as a constant function in a neighbourhood of each of those x0x_{0}’s. The precise result is summarised in the following proposition:

There exist functions f:(0,1)→(0,1)f:{(0,1)}\to{(0,1)} and g:(0,1)→g:{(0,1)}\to{} such that ff and gg are differentiable almost everywhere and continuous, but g∘fg\circ f fails to be almost-everywhere differentiable.

Returning to the proof, let ff be the inverse of the homeomorphism F : (0,1) → (0,1)F\,{:}\,{(0,1)}\,{\to}\,{(0,1)} defined by F(x) = 12(ϕ1(x)+x)F(x)\,{=}\,\frac{1}{2}(\phi_{1}(x)+x) [8, Example 2.3.1]. It is known that f(C1/2) = C1f(C_{1/2})\,{=}\,C_{1} [8, Example 2.3.2]. Construct g:(0,1)→g:{(0,1)}\to based on the construction of C1C_{1} as follows, similarly to [18, Example 8.18]: at each step k>0k>0, define gg over the ii-th open interval (li,ri)(l_{i},r_{i}) to be removed, as g(y)=2−k⋅[1−(y−(ri+li)/2)2/((ri−li)/2)2]g(y)=2^{-k}\cdot[1-(y-(r_{i}+l_{i})/2)^{2}/((r_{i}-l_{i})/2)^{2}] (i∈[2k−1]i\in[2^{k-1}]); and define gg over C1C_{1} as g(y)=0g(y)=0. See Figure 1 for the graphs of ϕ1\phi_{1}, ff, and gg constructed so far. Clearly, ff is continuous. Also, gg is continuous, since the height of the parabolas defined at the kk-th step of gg’s construction converges to as k→∞k\to\infty, and g(C1)={0}g(C_{1})=\{0\} (see Appendix A for the details). Hence, g∘fg\circ f is continuous. Note that ff is even Lipschitz continuous. To prove this, observe that ff can be constructed similarly to ϕ1/2\phi_{1/2}, and repeat the proof of the Lipschitz continuity of ϕ1/2\phi_{1/2} .

We now show that ff and gg are differentiable almost everywhere, but g∘fg\circ f is not. First, since ff is Lipschitz continuous, it is differentiable almost everywhere by Rademacher’s theorem [41, Theorem 2.2.4]. Next, since gg is differentiable on (0,1) ∖C1{(0,1)}\,\setminus C_{1} by its construction, it is differentiable almost everywhere (as C1C_{1} has measure ). Lastly, g∘fg\circ f is non-differentiable on C1/2C_{1/2}, which has measure 1/21/2, due to that: the parabolas defined at the kk-th step of gg’s construction get sharper as k→∞k\to\infty; g(C1)={0}g(C_{1})=\{0\}; and ff is a homeomorphism with f(C1/2)=C1f(C_{1/2})=C_{1} (see Appendix A for the details). ∎

If ff, gg, and g∘fg\circ f are differentiable almost everywhere and continuous, then the standard chain rule for g∘fg\circ f should hold almost everywhere. In particular, if f,g:(0,1)→(0,1)f,g:{(0,1)}\to{(0,1)}, then (g∘f)′(x0)=g′(f(x0))⋅f′(x0)(g\circ f)^{\prime}(x_{0})=g^{\prime}(f(x_{0}))\cdot f^{\prime}(x_{0}) for almost all x0∈(0,1)x_{0}\in{(0,1)}.

Note that all of ff, gg, and g∘fg\circ f in the claim are assumed to be differentiable almost everywhere. The claim comes from heuristic reasoning that if we just avoid those rare non-differentiable inputs of g∘fg\circ f, we should be able to use the standard result for differentiation, including the chain rule.

The second claim is also wrong. The flaw in the heuristic reasoning from above is that the almost-everywhere differentiability of ff, gg, and g∘fg\circ f does not stop g′(f(x0))g^{\prime}(f(x_{0})) from being undefined for many x0x_{0}’s in (0,1){(0,1)}. This is related to the flaw in the justification for the first claim that we explained. The next proposition and its proof provide a concrete example for this phenomenon:

There exist functions f,g:(0,1)→(0,1)f,g:{(0,1)}\to{(0,1)} such that ff, gg, and g∘fg\circ f are differentiable almost everywhere and continuous, but it is not that g′(f(x))g^{\prime}(f(x)) is defined for almost all x∈(0,1)x\in{(0,1)}.

Let f(x)=1/2f(x)=1/2 and g(y)=ReLU(y−1/2)+1/2g(y)={\rm ReLU}(y-1/2)+1/2. Then, (g∘f)(x)=1/2(g\circ f)(x)=1/2. Certainly, ff, gg, and g∘fg\circ f are differentiable almost everywhere and Lipschitz continuous. But, gg is not differentiable at f(x)=1/2f(x)=1/2 for all x∈(0,1)x\in(0,1). So, it is not that g′(f(x))g^{\prime}(f(x)) is defined for almost all x∈(0,1)x\in(0,1). ∎

The third claim is a natural reaction to the failure of the second claim. It implements the strategy of making the chain rule in the second claim more permissive such that the counter argument of Proposition 2 no longer applies. The claim expresses a weaker version of the rule that allows one to set the derivatives of ff and gg to arbitrary values wherever ff and gg are not differentiable.

The functions df\mathit{df} and dg\mathit{dg} in the claim are the extensions of f′f^{\prime} and g′g^{\prime} that set df(x)\mathit{df}(x) and dg(y)\mathit{dg}(y) to arbitrary values whenever f′(x)f^{\prime}(x) and g′(y)g^{\prime}(y) are undefined. The chain rule in the claim is phrased in terms of these extensions df\mathit{df} and dg\mathit{dg}, so that it does not suffer from the problem pointed out in Proposition 2. However, this new rule is still flawed as shown in the next proposition:

There exist functions f,g:(0,1)→(0,1)f,g:{(0,1)}\to{(0,1)} such that ff, gg, and g∘fg\circ f are differentiable almost everywhere and continuous, but for some measurable subset A⊆(0,1)A\subseteq{(0,1)} with non-zero measure, they satisfy the following property: f′(x)=0f^{\prime}(x)=0 and (g∘f)′(x)≠0(g\circ f)^{\prime}(x)\neq 0 for all x∈Ax\in A.

Consider the function ff in the proof of Proposition 1. Let gg be the 11-Cantor function ϕ1\phi_{1}. Then, g∘fg\circ f is the (1/2)(1/2)-Cantor function ϕ1/2\phi_{1/2}. We already showed ff is differentiable almost everywhere and even Lipschitz continuous. Since gg and g∘fg\circ f are monotone on (0,1){(0,1)}, they are differentiable almost everywhere by the monotone differentiation theorem [41, Theorem 1.6.25]; and they are clearly continuous. We now show there exists A⊆C1/2A\subseteq C_{1/2} with the desired properties. Since C1/2C_{1/2} has measure 1/21/2, it suffices to prove f′(x)=0f^{\prime}(x)=0 and (g∘f)′(x)=2(g\circ f)^{\prime}(x)=2 for almost all x∈C1/2x\in C_{1/2}. The claim indeed holds due to the following: ff and g∘fg\circ f are Lipschitz, so absolutely continuous; f′(x)=2f^{\prime}(x)=2 and (g∘f)′(x)=0(g\circ f)^{\prime}(x)=0 for all x∉C1/2x\notin C_{1/2}; f′(x)≥0f^{\prime}(x)\geq 0 and (g∘f)′(x)≤2(g\circ f)^{\prime}(x)\leq 2 for all x∈C1/2x\in C_{1/2} whenever these derivatives exist; and C1/2C_{1/2} has measure 1/21/2. For the details, see [8, Example 2.3.2] and . ∎

The proposition implies the third claim is doomed. The claim says that df(x0)=f′(x0)\mathit{df}(x_{0})=f^{\prime}(x_{0}) and (g∘f)′(x0)=dg(f(x0))⋅df(x0)(g\circ f)^{\prime}(x_{0})=\mathit{dg}(f(x_{0}))\cdot\mathit{df}(x_{0}) for almost all x0∈Ax_{0}\in A. But both equalities cannot hold simultaneously: if they do, by Proposition 3, (g∘f)′(x0)=dg(f(x0))⋅df(x0)=dg(f(x0))⋅f′(x0)=dg(f(x0))⋅0=0,(g\circ f)^{\prime}(x_{0})=\mathit{dg}(f(x_{0}))\cdot\mathit{df}(x_{0})=\mathit{dg}(f(x_{0}))\cdot f^{\prime}(x_{0})=\mathit{dg}(f(x_{0}))\cdot 0=0, but the same proposition also entails (g∘f)′(x0)≠0(g\circ f)^{\prime}(x_{0})\neq 0, leading to a contradiction.

A lesson from these flawed claims is that although the notion of correctness in Definition 1 only refers to almost-everywhere differentiability, we need a condition stronger than it, which behaves better in handling function composition and gives rise to a chain rule. We describe such a condition next.

PAP Function and Intensional Derivative

Our justification of autodiff systems relies on two key concepts: piecewise analyticity under analytic partition, and intensional derivative. The first is a (strictly) stronger property about functions than almost-everywhere differentiability, and yet it is satisfied by practically all programs targeted at by existing autodiff systems, as we will show in §4. Functions with this new property, called PAP functions, have an unusual type of derivatives, called intensional derivatives, which form the second concept. Intensional derivatives of PAP functions are defined everywhere and satisfy a chain rule, while still agreeing with standard derivatives for almost all inputs. In fact, the PAP functions have not just first-order but also all higher-order intensional derivatives. In §4, we will show that most autodiff systems compute intensional derivatives when applied to functions with non-differentiabilities.

To expand the overview of the two concepts just given, we need a notion of piecewise representation:

A representation γ={⟨Ai,fi⟩}i∈[I]\gamma=\{\langle A^{i},f^{i}\rangle\}_{i\in[I]} from X\mathcal{X} to Y\mathcal{Y} is piecewise analytic under analytic partition (in short, PAP) if and only if {Ai}i∈[I]\{A^{i}\}_{i\in[I]} is an analytic partition of X\mathcal{X} and fif^{i} is analytic over its domain Xi\mathcal{X}^{i} for all i∈[I]i\in[I].

The definitions identify PAP representations and PAP functions as those built by the two-step process: we first split the input domain such that boundaries of the split regions are expressed by the zero sets of analytic functions, and next choose an appropriate analytic function for each piece of the split. Note the use of analytic functions in both steps. Thus, just like the standard analyticity, the PAP property implies almost-everywhere differentiability (Proposition 4), but not vice versa (Proposition 5).

All PAP functions are differentiable almost everywhere.

The proof extends the one for a similar result in . The key idea is to use the fact that the zero set of a non-constant analytic function over a connected open domain has measure zero . To prove the proposition, we show that for each PAP function ff, there exist countably many non-constant analytic functions {gj}j\{g_{j}\}_{j} over connected open domains such that if ff is non-differentiable at x∈Xx\in\mathcal{X}, then xx belongs to the zero set of some gjg_{j}. For the details, see Appendix B.3. ∎

There is a continuous almost-everywhere differentiable yet non-PAP function.

Nearly all the requirements for DγD\gamma to be a PAP representation directly follow from the fact that γ\gamma is PAP. The only exception is the analyticity of DfiDf^{i}. There we use the fact that the operation of taking a (standard) partial derivative of a function preserves analyticity [25, Proposition 2.2.3]. ∎

By Proposition 6, only PAP functions live in ∂∙f\partial_{\bullet}{f}. Thus, we can also take intensional derivatives of functions in ∂∙f\partial_{\bullet}{f}. We push this observation further and define higher-order intensional derivatives:

The first claim is proven similarly to Proposition 4, except that we additionally use the following: an analytic function is infinitely differentiable. As in Proposition 4, we prove a stronger statement: there exist countably many non-constant analytic functions {gj}j\{g_{j}\}_{j} over connected open domains such that for all kk, if the kk-th order standard derivative of ff is not defined at x∈Xx\in\mathcal{X}, then xx is in the zero set of some gjg_{j}. Next, consider the second claim. Its current form is not strong enough to enable inductive proofs. We instead prove a stronger statement by induction on kk: for each dfk∈∂∙kf\mathit{df}^{k}\in\partial_{\bullet}^{{k}}f, there exist countably many non-constant analytic functions {hl}l\{h_{l}\}_{l} over connected open domains such that the kk-th order standard derivative of ff is well-defined, and agrees with dfk\mathit{df}^{k}, at all those inputs not in the zero sets of {hl}l\{h_{l}\}_{l}. For the details, see Appendices B.3 and B.4. ∎

Since ff and gg are PAP, they have PAP representations γf={⟨Ai,fi⟩}i∈[I]\gamma_{f}=\{\langle A^{i},f^{i}\rangle\}_{i\in[I]} and γg={⟨Bj,gj⟩}j∈[J]\gamma_{g}=\{\langle B^{j},g^{j}\rangle\}_{j\in[J]}. Define their composition as follows: γg∘γf={⟨C⟨i,j⟩,gj∘fi⟩}⟨i,j⟩∈[I]×[J]\gamma_{g}\circ\gamma_{f}=\{\langle C^{\langle i,j\rangle},g^{j}\circ f^{i}\rangle\}_{\langle i,j\rangle\in[I]\times[J]} where C⟨i,j⟩={x∈X∣x∈Ai∧fi(x)∈Bj}C^{\langle i,j\rangle}=\{x\in\mathcal{X}\mid x\in A^{i}\land f^{i}(x)\in B^{j}\}. Then, γg∘γf\gamma_{g}\circ\gamma_{f} is a representation of g∘fg\circ f. Also, it is PAP as the composition of analytic functions is analytic [25, Proposition 2.2.8]. Thus, g∘fg\circ f is PAP. ∎

We next use these properties to show that existing autodiff systems compute intensional derivatives.

Correctness of Autodiff Systems

Consider a simple programming language that assumes real-valued input variables x1,…,xNx_{1},\ldots,x_{N} and has the following syntax for programs: e ::= c ∣ xi ∣ \accentsetf(e1,…,en) ∣ if (e1>0) e2 e3.e\,::=\,{c}\,\mid\,{x}_{i}\,\mid\,\accentset{\rule{2.79996pt}{0.8pt}}{\mathtt{f}}(e_{1},\ldots,e_{n})\,\mid\,\mathtt{if}~{}(e_{1}>0)~{}e_{2}~{}e_{3}.

\begin{array}[]{@{}c@{}}\llbracket{c}\rrbracket v=c,\qquad\llbracket{x_{i}}\rrbracket v=v_{i},\qquad\llbracket{\accentset{\rule{2.79996pt}{0.8pt}}{\mathtt{f}}(e_{1},\ldots,e_{n})}\rrbracket v={\mathtt{f}}(\llbracket{e_{1}}\rrbracket v,\ldots,\llbracket{e_{n}}\rrbracket v),\\[3.00003pt] \llbracket{\mathtt{if}~{}(e_{1}>0)~{}e_{2}~{}e_{3}}\rrbracket v=\text{if }(\llbracket{e_{1}}\rrbracket v>0)\text{ then }\llbracket{e_{2}}\rrbracket v\text{ else }\llbracket{e_{3}}\rrbracket v.\end{array}

\begin{array}[]{@{}c@{}}\llbracket{c}\rrbracket^{\nabla}\;\!\!v=\vec{0}_{1\times N},\quad\llbracket{\accentset{\rule{2.79996pt}{0.8pt}}{\mathtt{f}}(e_{1},\ldots,e_{n})}\rrbracket^{\nabla}\;\!\!v=(\mathchoice{\accentset{\displaystyle\text{\smash[b]{\raisebox{-6.24301pt}{\widetildesym}}}}{D}}{\accentset{\textstyle\text{\smash[b]{\raisebox{-6.24301pt}{\widetildesym}}}}{D}}{\accentset{\scriptstyle\text{\smash[b]{\raisebox{-4.37012pt}{\widetildesym}}}}{D}}{\accentset{\scriptscriptstyle\text{\smash[b]{\raisebox{-3.1215pt}{\widetildesym}}}}{D}}\mathtt{f})(\llbracket{e_{1}}\rrbracket v,\ldots,\llbracket{e_{n}}\rrbracket v)\cdot[\llbracket{e_{1}}\rrbracket^{\nabla}\;\!\!v;\,\ldots;\,\llbracket{e_{n}}\rrbracket^{\nabla}\;\!\!v],\\[3.00003pt] \llbracket{x_{i}}\rrbracket^{\nabla}\;\!\!v\,{=}\,[\vec{0}_{(i-1)\times 1};\vec{1}_{1\times 1};\vec{0}_{(N-i)\times 1}]^{\top}\!\!,\ \;\llbracket{\mathtt{if}\,(e_{1}{>}0)\,e_{2}\,e_{3}}\rrbracket^{\nabla}\;\!\!v\,{=}\,\text{if}\,(\llbracket{e_{1}}\rrbracket v{>}0)\,\text{then}\,{\llbracket{e_{2}}\rrbracket^{\nabla}\;\!\!}v\text{ else}\,{\llbracket{e_{3}}\rrbracket^{\nabla}\;\!\!}v.\end{array}

If \mathchoice{\accentset{\displaystyle\text{\smash[b]{\raisebox{-6.24301pt}{\widetildesym}}}}{D}}{\accentset{\textstyle\text{\smash[b]{\raisebox{-6.24301pt}{\widetildesym}}}}{D}}{\accentset{\scriptstyle\text{\smash[b]{\raisebox{-4.37012pt}{\widetildesym}}}}{D}}{\accentset{\scriptscriptstyle\text{\smash[b]{\raisebox{-3.1215pt}{\widetildesym}}}}{D}}\mathtt{f}\in\partial_{\bullet}{{\mathtt{f}}} for all primitive functions \accentsetf\accentset{\rule{2.79996pt}{0.8pt}}{\mathtt{f}}, then ⟦e⟧∇   ⁣ ⁣∈∂∙⟦e⟧\llbracket{e}\rrbracket^{\nabla}\;\!\!\in\partial_{\bullet}{\llbracket{e}\rrbracket} for all programs ee.

Related Work and Discussion

Autodiff has a long history with a large body of literature . Its community has been aware of some issues with non-differentiable functions [20, Chapter 14]. These issues have become ever more important, as autodiff has been increasingly applied to a variety of non-differentiable functions, including sophisticated linear algebra functions . In this paper, we investigate the issues in a more systematic and rigorous way, by presenting non-trivial concrete counterexamples that illuminate subtleties of non-differentiable functions in autodiff, and also proposing intensional derivatives, a new notion of derivatives, that enable us to formally prove the correctness of, and better understand the behaviour of, autodiff systems applied to non-differentiable functions.

Recently and concurrently with this work, Bolte and Pauwels studied some concepts and results similar to ours. They proposed a new class of functions and a new notion of derivatives, called elementary selections and selection derivatives, which roughly correspond to our PAP functions and intensional derivatives; and proved properties of those new functions and derivatives, which roughly correspond to our Propositions 8, 9, 10, 11 and 12. Although having some similarities, our work and their work have three key differences, complementing each other. First, their work is applicable to a strictly smaller class of functions than ours, as any elementary selection is PAP (and locally Lipschitz) but not vice versa. Second, it considers selection derivatives of first order only, whereas our work considers intensional derivatives of higher orders as well. Third, their work provides some results not in our work (e.g., convergence of stochastic gradient descent with selection derivatives), and vice versa (e.g., the results in §2).

Broader Impact

This work focuses mainly on theoretical aspects of autodiff systems. In particular, we formally prove that the systems, though developed to handle differentiable functions, remain correct even when applied to non-differentiable functions. Our result justifies, at least in part, the current situation in machine learning, in which the systems are frequently applied to non-differentiable functions without much consideration to their correctness under such out-of-scope use cases. Other than the justification, this work does not present any other foreseeable societal consequence due to its theoretical nature.

Acknowledgments and Disclosure of Funding

We thank anonymous reviewers for their insightful and constructive comments. Lee, Yang, and Yu were supported by the Engineering Research Center Program through the National Research Foundation of Korea (NRF) funded by the Korean Government MSIT (NRF-2018R1A5A1059921), and also by Next-Generation Information Computing Development Program through the National Research Foundation of Korea (NRF) funded by the Ministry of Science, ICT (2017M3C4A7068177). Rival was supported by a Facebook gift and by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 825492).

References

Appendix A Comments on Results in §2

First, we elaborate on our proof in Proposition 1 that gg is continuous on (0,1)(0,1). Since gg is continuous on (0,1)∖C1(0,1)\setminus C_{1} by its construction, we only need to show that gg is continuous on C1C_{1}. Consider any x∈C1x\in C_{1} and ϵ>0\epsilon>0. It suffices to show that there is δ∈(0,x)\delta\in(0,x) such that

Let k>0k>0 be an integer with 2−k<ϵ2^{-k}<\epsilon. Consider the set

By the construction of gg, SS is the union of some finitely many closed intervals in (0,1)(0,1) that do not contain xx. (Note that each of those closed intervals is contained in an open interval removed at some k′(≤k)k^{\prime}(\leq k)-th step of gg’s construction.) Hence,

is positive. We now show that δ\delta satisfies (1). Consider any x′x^{\prime} with 0<∣x−x′∣<δ0<|x-x^{\prime}|<\delta. If x′∈C1x^{\prime}\in C_{1}, then g(x′)=0g(x^{\prime})=0. If x′∉C1x^{\prime}\notin C_{1}, then x′∈(0,1)∖C1x^{\prime}\in(0,1)\setminus C_{1} and x′∉Sx^{\prime}\notin S by the definition of δ\delta, and thus g(x′)<2−k<ϵg(x^{\prime})<2^{-k}<\epsilon by the definition of SS and kk. Hence, (1) holds and this completes the proof. ∎

Second, we elaborate on our proof in Proposition 1 that g∘fg\circ f is not differentiable on C1/2C_{1/2}. Consider any x∈C1/2x\in C_{1/2}. It suffices to show that for any δ∈(0,x)\delta\in(0,x), there exist x1,x2∈(x−δ,x+δ)∖{x}x_{1},x_{2}\in(x-\delta,x+\delta)\setminus\{x\} such that

Consider any δ∈(0,x)\delta\in(0,x). Since x∈C1/2x\in C_{1/2} is a limit point of C1/2C_{1/2}, there exists x1∈(x−δ,x+δ)∖{x}x_{1}\in(x-\delta,x+\delta)\setminus\{x\} with x1∈C1/2x_{1}\in C_{1/2}. For this x1x_{1}, the first equality in (2) holds, since (g∘f)(C1/2)=g(C1)={0}(g\circ f)(C_{1/2})=g(C_{1})=\{0\}. To find x2x_{2}, let k>0k>0 be an integer such that

We claim that there exists x2∈(0,1)x_{2}\in(0,1) such that

and thus the second equality in (2) holds. Hence, finding x2∈(0,1)x_{2}\in(0,1) satisfying (4) completes the proof. We now show that such x2x_{2} exists. Consider the situation right after the kk-th step of C1/2C_{1/2}’s construction is performed. Then, the total length of the closed intervals that still remain is

so the length of each of those closed intervals is 12(2−k+3−k)\frac{1}{2}(2^{-k}+3^{-k}), since those closed intervals have the same length and there are 2k2^{k} such intervals. Due to this, and by the construction of C1/2C_{1/2}, there is some open interval II that is removed exactly at the kk-th step of C1/2C_{1/2}’s construction and satisfies

Let x2∈(0,1)x_{2}\in(0,1) be the midpoint of II. By the construction of ff and gg, we have (g∘f)(x2)=2−k(g\circ f)(x_{2})=2^{-k}. Furthermore, since the length of II is 3−k/23^{-k}/2, we have

Hence, x2∈(0,1)x_{2}\in(0,1) satisfies (4), and this concludes the proof. ∎

Next, we make a remark on non-differentiable inputs of ff, gg, and g∘fg\circ f in the proof. One might guess that ff should be non-differentiable exactly on C1/2C_{1/2}, given that ff maps (0,1) ∖C1/2{(0,1)}\,\setminus C_{1/2} onto (0,1) ∖C1{(0,1)}\,\setminus C_{1} in a linear way and maps C1/2C_{1/2} onto C1C_{1} in a non-smooth-looking way. Surprisingly, the guess is wrong: ff is in fact non-differentiable only on a measure-zero subset of C1/2C_{1/2}. On the other hand, gg and g∘fg\circ f are non-differentiable exactly on C1C_{1} and C1/2C_{1/2}, respectively. The proof that gg is non-differentiable on C1C_{1} is similar to the above proof that g∘fg\circ f is non-differentiable on C1/2C_{1/2}, and thus we omit it.

Finally, we connect the examples in the proof with our results in §3. Both ff and gg are shown to be non-PAP (Proposition 5). Hence, our results do not guarantee that g∘fg\circ f is PAP and so almost-everywhere differentiable. In fact, g∘fg\circ f is non-PAP, since g∘fg\circ f is not almost-everywhere differentiable.

A.2 Comments on the proof of Proposition 2

We explain how the counterexample in the proof does not contradict to our results in §3. The functions ff and gg are PAP (and thus g∘fg\circ f is so). Although g′g^{\prime} is undefined at , we can extend it to an intensional derivative dg∈∂∙g\mathit{dg}\in\partial_{\bullet}{g} such that dg\mathit{dg} is defined everywhere (even at ) and coincides with g′g^{\prime} at all but countably many inputs. With such dg\mathit{dg}, the following version of the chain rule holds almost everywhere:

This is because we have the chain rule for intensional derivatives and and these intensional derivatives and standard derivatives coincide almost everywhere (Propositions 10 and 8).

A.3 Comments on the proof of Proposition 3

The functions ff, gg, and g∘fg\circ f in the proof do not contradict to our results. Neither ff nor gg is a PAP function (Proposition 5). Hence, our results do not guarantee the validity of our version of the chain rule for g∘fg\circ f.

Appendix B Comments on and Proofs for Results in §3

We prove the following argument used in the proof of Proposition 5: the functions listed in the proof satisfy the sufficient condition (i) or (ii) mentioned in the proof.

has positive measure. For the λ\lambda-Cantor function ϕλ\phi_{\lambda} with λ∈(0,1)\lambda\in(0,1), SS is a full measure subset of CλC_{\lambda} due to the following: ϕλ′(x)=1/(1−λ)≠0\phi_{\lambda}^{\prime}(x)=1/(1-\lambda)\neq 0 for almost all x∈Cλx\in C_{\lambda}; ϕλ′(x)=0\phi_{\lambda}^{\prime}(x)=0 for all x∉Cλx\notin C_{\lambda}; and Cλ⊂(0,1)C_{\lambda}\subset(0,1) has no interior. Since CλC_{\lambda} has measure 1−λ>01-\lambda>0, the claim holds for ϕλ\phi_{\lambda}. For ff in the proof of Proposition 1, SS is a full measure subset of C1/2C_{1/2} due to similar reasons. So the claim holds for ff. For Volterra’s function, SS is known to have positive measure [18, Example 8.35]. So the claim holds for Volterra’s function.

B.2 Interior and subinterior of analytic partition

Then, C={Ct}t∈[T]C=\{C^{t}\}_{t\in[T]} is a finer partition of X\mathcal{X} than {Ai}i∈[I]\{A^{i}\}_{i\in[I]}. That is, CC is a partition of X\mathcal{X}, and for all t∈[T]t\in[T], Ct⊆AiC^{t}\subseteq A^{i} for some i∈[I]i\in[I].

We call the set X′\mathcal{X}^{\prime} a subinterior of AA, and the partition BB a subanalytic partition of X′\mathcal{X}^{\prime}. We use subint(A){\rm subint}({A}) to denote the set of all subinteriors of AA.

X∖X′\mathcal{X}\setminus\mathcal{X}^{\prime} is contained in some measure-zero set.

X∖int(A)\mathcal{X}\setminus{\rm int}({A}) is contained in some measure-zero set.

Then, X′\mathcal{X}^{\prime} is a subinterior of AA, and BB is a subanalytic partition of X′\mathcal{X}^{\prime}, because of the following:

BB is a partition of X′\mathcal{X}^{\prime}.

{⟨i,t1,…,tLi⟩∣i∈[I],  ⟨t1,…,tLi⟩∈[∞]Li}\{\langle i,t_{1},\ldots,t_{L_{i}}\rangle\mid i\in[I],\;\langle t_{1},\ldots,t_{L_{i}}\rangle\in[\infty]^{L_{i}}\} is a countable set.

For all i∈[I]i\in[I] and ⟨t1,…,tLi⟩∈[∞]Li\langle t_{1},\ldots,t_{L_{i}}\rangle\in[\infty]^{L_{i}}, Bi,⟨t1,…,tLi⟩B^{i,\langle t_{1},\ldots,t_{L_{i}}\rangle} is subanalytic.

CC is a finer partition of X\mathcal{X} than AA. This holds because {Ai}i∈[I]\{A^{i}\}_{i\in[I]} is a partition of X\mathcal{X}, and {Ci,⟨t1,…,tLi⟩}⟨t1,…,tLi⟩∈[∞]Li\{C^{i,\langle t_{1},\ldots,t_{L_{i}}\rangle}\}_{\langle t_{1},\ldots,t_{L_{i}}\rangle\in[\infty]^{L_{i}}} is a partition of AiA^{i} for all i∈[I]i\in[I], by its construction.

This completes the proof that subint(A)≠∅{\rm subint}({A})\neq\varnothing.

We now prove the remaining claims. Let X′∈subint(A)\mathcal{X}^{\prime}\in{\rm subint}({A}) and B={Bt}t∈[T]B=\{B^{t}\}_{t\in[T]} be a subanalytic partition of X′\mathcal{X}^{\prime} that satisfies the equations in Definition 10.

Since each gt,l−g^{-}_{t,l} is analytic, and not everywhere-zero, on its connected open domain Xt,l−\mathcal{X}^{-}_{t,l} (by the definition of subanalytic partition), the above theorem and equation imply that (gt,l−)−1({0})(g^{-}_{t,l})^{-1}(\{0\}) is contained in some measure-zero set. Since any countable union of measure-zero sets has measure zero, X∖X′\mathcal{X}\setminus\mathcal{X}^{\prime} is contained in some measure-zero set.

Proof of (d). This follows immediately from (b) and (c). ∎

B.3 Proofs of Proposition 4 and Proposition 8 (part I)

We remind the reader that the notation D(f)(x)D(f)(x) means the standard derivative of ff at xx.

Let γ={⟨Ai,fi⟩}i∈[I]\gamma=\{\langle A^{i},f^{i}\rangle\}_{i\in[I]} be a PAP representation from X\mathcal{X} to Y\mathcal{Y}. The interior and subinterior of γ\gamma are defined by:

where F(k)F^{(k)} denotes the kk-time composition of the operator FF.

B.4 Proof of Proposition 8 (part II)

Let f:Xf→Yf:\mathcal{X}_{f}\to\mathcal{Y} and g:Xg→Yg:\mathcal{X}_{g}\to\mathcal{Y} be PAP functions, and γf\gamma_{f} and γg\gamma_{g} be their PAP representations. If f(x)=g(x)f(x)=g(x) for all x∈int(γf)∩int(γg)x\in{\rm int}({\gamma_{f}})\cap{\rm int}({\gamma_{g}}), then

where both sides are well-defined for each xx.

Let f:X→Yf:\mathcal{X}\to\mathcal{Y} be a PAP function. Then, for any intensional derivative df∈∂∙f\mathit{df}\in\partial_{\bullet}{f}, there exists a PAP representation γdf\gamma_{\mathit{df}} of df\mathit{df} such that

Let γf={⟨Ai,fi⟩}i∈[I]\gamma_{f}=\{\langle A^{i},f^{i}\rangle\}_{i\in[I]} be a representation of a function from Xf\mathcal{X}_{f} to Y\mathcal{Y}, and B={Bj}j∈[J]B=\{B^{j}\}_{j\in[J]} be a partition of Xg\mathcal{X}_{g}. The refinement of γf\gamma_{f} with BB is defined by:

Moreover, for any representation γg={⟨Cl,gl⟩}l∈[L]\gamma_{g}=\{\langle C^{l},g^{l}\rangle\}_{l\in[L]} of a function from Xg\mathcal{X}_{g} to Z\mathcal{Z}, the refinement of γf\gamma_{f} with γg\gamma_{g} is defined by:

Let γ={⟨Ai,fi⟩}i∈[I]\gamma=\{\langle A^{i},f^{i}\rangle\}_{i\in[I]}. Since γ\gamma is PAP and BB is an analytic partition, {Ai∩Bj}⟨i,j⟩∈[I]×[J]\{A^{i}\cap B^{j}\}_{\langle i,j\rangle\in[I]\times[J]} is an analytic partition. Also, since [J][J] is countable, [I]×[J][I]\times[J] is also countable. Thus, γ′\gamma^{\prime} is PAP. Since

γ′\gamma^{\prime} is a representation of f∣Xf∩Xg{f|_{\mathcal{X}_{f}\cap\mathcal{X}_{g}}}. Finally, we obtain the last claim as follows:

For the second equality, we use the following fact: int(S1∩S2;X)=int(S1;X)∩int(S2;X){\rm int}({S_{1}\cap S_{2};X})={\rm int}({S_{1};X})\cap{\rm int}({S_{2};X}) for any S1,S2⊆XS_{1},S_{2}\subseteq X. ∎

The proof proceeds by induction on kk. For k=0k=0, we have dfk=D(k)(f)=f\mathit{df}^{k}=D^{(k)}(f)=f. So any PAP representation γdk\gamma_{d}^{k} of dfk=f\mathit{df}^{k}=f satisfies the claim. Now suppose k>0k>0. By the definition of ∂∙kf\partial_{\bullet}^{{k}}{f}, there exists dfk−1∈∂∙k−1f\mathit{df}^{k-1}\in\partial_{\bullet}^{{k-1}}{f} such that dfk∈∂∙(dfk−1)\mathit{df}^{k}\in\partial_{\bullet}{(\mathit{df}^{k-1})}. We construct the desired PAP representation γdk\gamma_{d}^{k} as follows. First, focus on dfk−1∈∂∙k−1f\mathit{df}^{k-1}\in\partial_{\bullet}^{{k-1}}{f}. By the induction hypothesis on k−1k-1 for dfk−1\mathit{df}^{k-1}, there exists a PAP representation γdk−1\gamma_{d}^{k-1} of dfk−1\mathit{df}^{k-1} such that

The claim follows from Lemma 21 and the following: X′\mathcal{X}^{\prime} and int(γdk){\rm int}({\gamma_{d}^{k}}) described in Lemma 21 have the full measure in X\mathcal{X}, by Lemma 21 and Lemma 14(d). ∎

B.5 Additional property on PAP functions