Fixing Incremental Computation: Derivatives of Fixpoints, and the Recursive Semantics of Datalog

Incremental computation has recently been studied using the concepts of change structures and derivatives of programs, where the derivative of a function allows updating the output of the function based on a change to its input. We generalise change structures to change actions, and study their algebraic properties. We develop change actions for common structures in computer science, including directed-complete partial orders and Boolean algebras. We then show how to compute derivatives of fixpoints. This allows us to perform incremental evaluation and maintenance of recursively defined functions with particular application to generalised Datalog programs. Moreover, unlike previous results, our techniques are modular in that they are easy to apply both to variants of Datalog and to other programming languages.


INTRODUCTION
Consider the following classic Datalog program 1 , which computes the transitive closure of an edge relation e: tc(x, y) ← e(x, y) tc(x, y) ← e(x, z) ∧ tc(z, y) The semantics of Datalog tells us that the denotation of this program is the least fixpoint of the rule tc. Kleene's Theorem tells us that we can compute this fixpoint by repeatedly applying the rule until it stops changing, starting from the empty relation. (as above) (as above) At this point we have reached a fixpoint, and so we are done. However, this process is quite wasteful. We deduced the fact (1, 2) at every iteration, even though we had already deduced it in the first iteration. Indeed, for a chain of n such edges we will deduce O(n 2 ) facts along the way.
The standard improvement to this evaluation strategy is known as "semi-naive" evaluation[See 1, section 13.1], where we transform the program into a delta program with two parts: • A delta rule that computes the new facts at each iteration.
• An accumulator rule that accumulates the delta at each iteration to compute the final result In this case our delta rule is simple: we only get new transitive edges at iteration n + 1 if we can deduce them from transitive edges we deduced at iteration n. This is much better -we have turned a quadratic computation into a linear one. The delta transformation is a kind of incremental computation: at each stage we compute the changes in the rule given the previous changes to its inputs.
But the delta rule translation works only for traditional Datalog. It is common to liberalise the formula syntax with additional features, such as disjunction, existential quantification, negation, and aggregation. 2 This allows us to write programs like the following, where we compute whether all the nodes in a subtree given by child have some property p: treeP(x) ← p(x) ∧ ¬∃y.(child(x, y) ∧ ¬treeP(y)) Here the combination of negation and explicit existential quantification amounts to recursion through a universal quantifier. We would like to be able to use semi-naive evaluation for this rule too, but the simple delta transformation is not well defined for the extended program syntax, and it is unclear how to extend it (and the correctness proof) to handle such cases. 3 It is possible, however, to write a delta program for treeP by hand; indeed, the following definition provides one: ∆ i+1 treeP(x) = p(x) ∧ ∃y.(child(x, y) ∧ ∆ i treeP(y)) ∧ ¬∃y.(child(x, y) ∧ ¬treeP i (y)) This is a correct delta program (in that using it to iteratively compute treeP gives the right answer), but it is not precise because it derives some facts repeatedly. We will show how to construct 2 See, for example, [24,30,LogiQL], [16,Datomic], [35,39,Souffle], and [33,DES], which between them have all of these features and more. 3 A simple approach is to just keep applying the algorithm of "replace each recursive call in turn with its delta, and take the union of each of those". But this is in fact incorrect and does not produce correct incremental programs in general.
Fixing incremental computation 1:3 correct delta programs generally using a program transformation, and show how we have some freedom to optimize within a range of possible alternatives to improve precision or ease evaluation.
Handling extended Datalog is of more than theoretical interest -the research in this paper was carried out at Semmle, which makes heavy use of a commercial Datalog implementation [5,34,36,37]. Semmle's implementation includes parity-stratified negation 4 , recursive aggregates [17], and other non-standard features, so we are faced with a dilemma: either abandon the new language features, or abandon incremental computation.
We can tell a similar story about maintenance of Datalog programs. Maintenance means updating the results of the program when its inputs change, for example, updating the value of tc given a change to e. Again, this is a kind of incremental computation, and there are known solutions for traditional Datalog [23], but these break down when the language is extended.
There is a piece of folkloric knowledge in the Datalog community that hints at a solution: the semi-naive translation of a rule corresponds to the derivative of that rule [6,7][section 3.2.2]. The idea of performing incremental computation using derivatives has been studied recently by Cai et al. [12], who give an account using change structures. They use this to provide a framework for incrementally evaluating lambda calculus programs.
However, Cai et al.'s work isn't directly applicable to Datalog: the tricky part of Datalog's semantics are recursive definitions and the need for the fixpoints, so we need some additional theory to tell us how to handle incremental evaluation and maintenance of fixpoint computations.
This paper aims to bridge that gap by providing a solid semantic foundation for the incremental computation of Datalog, and other recursive programs, in terms of changes and differentiable functions.

Contributions
We start by generalizing change structures to change actions (section 2). Change actions are simpler and weaker than change structures, while still providing enough structure to handle incremental computation, and have fruitful interactions with a variety of structures (section 3, section 6.1). In addition, change actions are not dependently typed (for more discussion of the differences, see section 9.1.1), which makes them easier to implement directly in a simply-typed language without type erasure.
We then show how change actions can be used to perform incremental evaluation and maintenance of non-recursive program semantics, using the formula semantics of generalized Datalog as our primary example (section 4). Moreover, the structure of the approach is modular, and can accommodate arbitrary additional formula constructs (section 4.3).
We also provide a method of incrementally computing and maintaining fixpoints (section 6.2). We use this to perform incremental evaluation and maintenance of recursive program semantics, including generalized recursive Datalog (section 7). This provides, to the best of our knowledge, the world's first incremental evaluation and maintenance mechanism for Datalog that can handle negation, disjunction, and existential quantification.
Finally, we provide some empirical evaluation of the effects of our changes (section 8).
We have omitted the proofs from this paper. Most of the results have routine proofs, but the proofs of the more substantial results (especially those in section 6.2) are included in an appendix.

CHANGE ACTIONS AND DERIVATIVES
Incremental computation requires understanding how values change. For example, we can change an integer by adding a natural to it. Abstractly, we have a set of values (the integers), and a set of changes (the naturals) which we can "apply" to a value (by addition) to get a new value.
This kind of structure is well-known -it is a set action. It is also very natural to want to combine changes sequentially, and if we do this then we find ourselves with a monoid action. 5

Change actions
where A is a set, ∆A is a monoid, and ⊕ A : A × ∆A → A is a monoid action on A. 6 We will call A the base set, and ∆A the change set of the change action. We will use · for the monoid operation of ∆A, and 0 for its identity element. When there is no risk of confusion, we will simply write ⊕ for ⊕ A .

Examples.
A typical example of a change action is (A * , A * , + +) where A * is the set of finite words (or lists) of A. Here we represent changes to a word made by concatenating another word onto it. The changes themselves can be combined using + + as the monoid operation with the empty word as the identity, and this is a monoid action: This is a very common case: any monoid (A, ·, 0) can be seen as a change action (A, (A, ·, 0), ·). Many practical change actions can be constructed in this way. In particular, for any change action (A, ∆A, ⊕), (∆A, ∆A, ·) is also a change action. This means that we don't have to do any extra work to talk about changes to changes -we can always take ∆∆A = ∆A.
Three examples of change actions are of particular interest to us. First, whenever L is a Boolean algebra, we can give it the change actions (L, L, ∨) and (L, L, ∧), as well as a combination of these (see section 3.2). Second, the natural numbers with addition have a change actionN (N, N, +), which will prove useful during inductive proofs.
Another interesting example of change actions is semiautomata. A semiautomaton is a triple (Q, Σ,T ), where Q is a set of states, Σ is a (non-empty) finite input alphabet and T : Q × Σ → Q is a transition function. Every semiautomaton corresponds to a change action (Q, Σ * ,T * ) on the free monoid over Σ * , with T * being the free extension of T . Conversely, every change actionÂ whose change set ∆A is freely generated by a finite set corresponds to a semiautomaton.
Other recurring examples of change actions are: where M is any monoid, which we call the empty change action on any base set, since it induces no changes at all.
where A is an arbitrary set, A → A denotes the set of all functions from A into itself, considered as a monoid under composition and ev is the usual evaluation map. We will call this the "full" change action on A since it contains every possible non-redundant change.
These are particularly relevant because they are, in a sense, the "smallest" and "largest" change actions that can be imposed on an arbitrary set A. 5 Using monoid actions for changes gives us a reason to think that change actions are an adequate representation of changes: any subset of A → A which is closed under composition can be represented as a monoid action on A, so we are able to capture all of these as change actions. 6 Why not just work with monoid actions? The reason is that while the category of monoid actions and the category of change actions have the same objects, they have different morphisms. See section 9.1.2 for further discussion. Many other notions in computer science can be understood naturally in terms of change actions, e.g. databases and database updates, files and diffs, Git repositories and commits, even video compression algorithms that encode a frame as a series of changes to the previous frame.

Derivatives
When we do incremental computation we are usually trying to save ourselves some work. We have an expensive function f : A → B, which we've evaluated at some point a. Now we are interested in evaluating f after some change δa to a, but ideally we want to avoid actually computing f (a ⊕ δa) directly.
A solution to this problem is a function f ′ : A × ∆A → ∆B, which given a and δa tells us how to change f (a) to f (a ⊕ δa). We call this a derivative of a function.
A function which has a derivative is differentiable, and we will writeÂ →B for the set of differentiable functions. 7 Derivatives need not be unique in general, so we will speak of "a" derivative. Functions into "thin" change actions -where a ⊕ δa = a ⊕ δb implies δa = δb -have unique derivatives, but many change actions are not thin. For example, because Derivatives capture the structure of incremental computation, but there are important operational considerations that affect whether using them for computation actually save us any work. As we will see in a moment (proposition 7), for many change actions we will have the option of picking the "worst" derivative, which merely computes f (a ⊕ δa) directly and then works out the change that maps f (a) to this new value. While this is formally a derivative, using it certainly does not save us any work! We will be concerned with both the possibility of constructing correct derivatives (section 3.2 and section 6.2 in particular), and also in giving ourselves a range of derivatives to choose from so that we can soundly optimize for operational value.
For our Datalog case study, we aim to cash out the folkloric idea that incremental computation functions via a derivative by constructing a good derivative of the semantics of Datalog. We will do this in stages: first the non-recursive formula semantics (section 4); and later the full, recursive, semantics (section 7).

Useful facts about change actions and derivatives
2.3.1 The Chain Rule. The derivative of a function can be computed compositionally, because derivatives satisfy the standard chain rule.
Theorem 3 (The Chain Rule). Let f :Â →B, д :B →Ĉ be differentiable functions. Then д • f is also differentiable, with a derivative given by 2.3.2 Complete change actions and minus operators. Complete change actions are an important class of change actions, because they have changes between any two values in the base set.

Definition 4.
A change action is complete if for any a, b ∈ A, there is a change δa ∈ ∆A such that a ⊕ δa = b.
Complete change actions have convenient "minus operators" that allow us to compute the difference between two values.
Proposition 6. LetÂ be a change action. Then the following are equivalent: •Â is complete.
• There is a minus operator onÂ. This last property is of the utmost importance, since we are often concerned with the differentiability of functions.
Proposition 7. Given a minus operator ⊖, and a function f , let Then f ′ ⊖ is a derivative for f .
The projection maps π 1 ,π 2 are differentiable with respect to it. Furthermore, a function f : A × B → C is differentiable fromÂ ×B intoĈ if and only if, for every fixed a ∈ A and b ∈ B, the partially applied functions Whenever f : A × B → C is differentiable, we will sometimes use ∂ 1 f and ∂ 2 f to refer to derivatives of the partially applied versions, i.e. if f ′ a : B × ∆B → ∆C and f ′ b : A × ∆A → ∆C refer to derivatives for f (a, ·), f (·, b) respectively, then ThenÂ +B (A + B, ∆A × ∆B, ⊕ + ) is a change action, where ⊕ + is defined as: The injection maps ι 1 , ι 2 are differentiable with respect toÂ +B. Furthermore, wheneverĈ is a change action and f : A → C, д : B → C are differentiable, then so is [f , д].

Comparing change actions
Much like topological spaces, we can compare change actions on the same base set according to coarseness. This is useful since differentiability of functions between change actions is characterized entirely by the coarseness of the actions. Definition 10. LetÂ 1 andÂ 2 be change actions on A. We say thatÂ 1 is coarser thanÂ 2 (or that A 2 is finer thanÂ 1 ) whenever for every x ∈ A and change δa 1 ∈ ∆A 1 , there is a change δa 2 ∈ ∆A 2 such that x ⊕ A 1 δa 1 = x ⊕ A 2 δa 2 .
The relation ≤ defines a preorder (but not a partial order) on the set of all change actions over a fixed set A. Least and greatest elements do exist up to equivalence, and correspond respectively to the empty change actionÂ ⊥ and any complete change action, such as the full change actionÂ ⊤ , defined in section 2.1. Proposition 11. LetÂ 2 ≤Â 1 ,B 1 ≤B 2 be change actions, and suppose the function f : A → B is differentiable as a function fromÂ 1 intoB 1 . Then f is differentiable as a function fromÂ 2 intoB 2 .
A consequence of this fact is that whenever two change actions are equivalent they can be used interchangeably without affecting which functions are differentiable. One last parallel with topology is the following result, which establishes a simple criterion for when a change action is coarser than another: Proposition 12. LetÂ 1 ,Â 2 be change actions on A. ThenÂ 1 is coarser thanÂ 2 if and only if the identity function id : A → A is differentiable fromÂ 1 toÂ 2 .

Change kernels and kernel orderings
Consider the full change actionẐ ⊤ on the integers. If we want to find a change that turns 99 into 100, there are a few options available: for example, we can pick the function λx .100, or the function λx .x + 1. In a sense, the first one does "too much" work, in that it captures all the information about the target value instead of just the difference between them.
This intuition that a change may do too much can be captured by the following definition: Definition 13. LetÂ be a change action and δa ∈ ∆A. Then the kernel of δa is the equivalence relation ∼ δ a on A defined by The kernel ordering on ∆A is defined by δa ≤ ∼ δb ⇐⇒ ∼ δ a ⊆ ∼ δ b We can use the kernel order, extended pointwise, to compare the different derivatives of a function. As we will see later (section 3.2), minimal derivatives under this order sometimes correspond to "precise" derivatives, in the sense of derivatives that do not produce excessively large changes.

POSETS AND BOOLEAN ALGEBRAS
The semantic domain of Datalog is a complete Boolean algebra, and so our next step is to construct a good change action for Boolean algebras. Along the way, we will consider change actions over posets, which give us the ability to approximate derivatives, which will turn out to be very important in practice.

Posets
Ordered sets give us a constrained class of functions: monotone functions. We can define ordered change actions, which are those that are well-behaved with respect to the order on the underlying set. 8 In fact, any change action whose base set is a poset induces a particularly convenient partial order on the corresponding change set: Proposition 16. LetÂ be a change action on a set A equipped with a partial order ≤ such that ⊕ is monotone in its first argument. ThenÂ is an ordered change action when ∆A is equipped with the partial order ≤ ∆ .
In what follows, we will extend the partial order ≤ ∆ on some change set ∆B pointwise to functions from some A into ∆B. This pointwise order interacts nicely with derivatives, in that it gives us the following lemma: Theorem 17 (Sandwich lemma). LetÂ be an change action, andB be an ordered change action, and given functions f : A → B and д : A × ∆A → ∆B. If f ↑ and f ↓ are derivatives for f such that If unique minimal and maximal derivatives exist, then this gives us a characterisation of all the derivatives for a function.
Theorem 18. LetÂ andB be change actions, withB ordered, and given a function f : A → B. If there exist f ↓↓ and f ↑↑ which are unique minimal and maximal derivatives of f , respectively, then the derivatives of f are precisely the functions f ′ such that This theorem gives us the leeway that we need when trying to pick a derivative: we can pick out the bounds, and that tells us how much "wiggle room" we have above and below.

Boolean algebras
Complete Boolean algebras are a particularly nice domain for change actions because they have a negation operator. This is very helpful for computing differences, and indeed Boolean algebras have a complete change action.
Proposition 19 (Boolean algebra change actions). Let L be a complete Boolean algebra. Definê ThenL ▷◁ is a complete change action on L.
We can think ofL ▷◁ as tracking changes as pairs of "upwards" and "downwards" changes, where the monoid action simply applies one after the other, with an adjustment to make sure that the components remain disjoint. 9 For example, in the powerset Boolean algebra P(N), a change to {1, 2} might consist of adding {3} and removing {1}, producing {2, 3}. In P(N) ▷◁ this would be represented as Boolean algebras also have unique maximal and minimal derivatives, under the usual partial order based on implication. 10 Proposition 20. Let L be a complete Boolean algebra with theL ▷◁ change action, and f : A → L be a function. Then, the following are minus operators: Additionally, f ′ ⊖ ⊥ and f ′ ⊖ ⊤ define unique least and greatest derivatives for f .

Theorem 18 then gives us bounds for all the derivatives on Boolean algebras:
Corollary 21. Let L be a complete Boolean algebra with the corresponding change actionL ▷◁ ,Â be an arbitrary change action, and f : A → L be a function. Then the derivatives of f are precisely those functions f ′ : This makes theorem 18 actually usable in practice, since we have concrete definitions for our bounds (which we will make use of in section 4.2).
Moreover, we have a nice definition of the kernel ordering, which gives us a minus operator with a corresponding precise derivative.
Definition 22. The pointwise order ≤ pt is the product order on L × L. 9 The intuition thatL ▷◁ is made up of an "upwards" and a "downwards" change action glued together can in fact be made precise, but the specifics are outside the scope of this paper. 10 The change set is, as usual, given the change partial order, which in this case corresponds to the natural order on L × L op . Proposition 23 (Boolean algebra kernels). Let L be a (complete) Boolean algebra with theL ▷◁ change action, f :Â →L a (differentiable) function, and suppose f ′ 1 and f ′ 2 are derivatives for f . Then f ′ 1 ≤ ∼ f ′ 2 (extending the kernel order pointwise to derivatives) iff for all a ∈ A and δa ∈ ∆A f ′ 1 (a, δa) ≤ pt f ′ 2 (a, δa) Additionally, the following is a minus operator, and f ′ ⊖ ∼ is a minimal derivative with respect to ≤ pt and ≤ ∼ : This shows us in what sense minimality with respect to the kernel ordering gives us precision: the precise derivative has components which are as small as possible (since it is also minimal with respect to ≤ pt ). When we are working with sets or relations, this is important since it corresponds to the actual size of components of the derivative.

DERIVATIVES FOR NON-RECURSIVE DATALOG
We now want to apply the theory we have developed to the specific case of the semantics of Datalog. Giving a differentiable semantics for Datalog will lead us to a strategy for performing incremental evaluation and maintenance of Datalog programs. To begin with, we will restrict ourselves to the non-recursive fragment of the language -the formulae that make up the right hand sides of Datalog rules. We will tackle the full program semantics in a later section, once we know how to handle fixpoints (section 7).
Although the techniques we are using should work for any language, Datalog provides a nontrivial case study where the need for incremental computation is real and pressing, as we saw in section 1.

Semantics of Datalog formulae
Datalog is usually given a logical semantics where formulae are interpreted as first-order logic predicates and the semantics of a program is the set of models of its constituent predicates. We will instead give a simple denotational semantics (as is typical when working with fixpoints [See e.g. 15]) that treats a Datalog formula as directly denoting a relation, i.e. a set of named tuples, with variables ranging over a finite schema.

Definition 24.
A schema Γ is a finite set of names. A named tuple over Γ is an assignment of a value v i for each name x i in Γ. Given disjoint schemata Γ = {x 1 , . . . , x n } and Σ = {y 1 , . . . , y m }, the selection function σ Γ is defined as I.e. σ Γ restricts a named tuple over Γ ∪ Σ into a tuple over Γ with the same values for the names in Γ. We denote the elementwise extension of σ Γ to sets of tuples also as σ Γ .
We will adopt the usual closed-world assumption to give a denotation to negation.  Since Rel Γ is a complete Boolean algebra, and so is Rel n Γ , T Γ is a function between complete Boolean algebras. For brevity, we will often leave the schema implicit, as it is clear from the context.

Differentiability of Datalog formula semantics
In order to actually perform our incremental computation, we first need to provide a concrete derivative for the semantics of Datalog formulae. Of course, since T Γ is a function between the complete Boolean algebras Rel n Γ and Rel Γ , and we know that the corresponding change actions Rel n Γ ▷◁ and Rel Γ ▷◁ are complete, this guarantees the existence of a derivative for T . Unfortunately, this does not necessarily provide us with an efficient derivative for T . The precise derivative that we know how to compute (proposition 23) relies on a minus operator: Naively computed, this expression requires computing f (a ⊕ δa) itself, which is the very thing we were trying to avoid computing! Of course, given a concrete definition of ⊖ ∼ we can simplify this expression and hopefully make it easier to compute. But we also know from corollary 21 that any function bounded by f ′ ⊖ ⊥ and f ′ ⊖ ⊤ is a valid derivative (f ′ ⊖ ∼ lies roughly in the middle of them), and we can therefore optimize anywhere within that range to make a trade-off between ease of computation and precision. The idea of using an approximation to the precise derivative, and a soundness condition, appears in Bancilhon and Ramakrishnan [7].
There is also the question of how to compute the derivative. Since the change set for Rel ▷◁ is a subset of Rel × Rel, it is possible and indeed very natural to compute the two components via a pair of Datalog formulae, which allows us to reuse an existing Datalog formula evaluator. Indeed, if this process is occurring in an optimizing compiler, the derivative formulae can themselves be optimized. This is very beneficial in practice, since the initial formulae may be quite complex.
This does give us additional constraints that the derivative formulae must satisfy: for example, we need to be able to evaluate them; and we may wish to pick formulae that will be easy or cheap for our evaluation engine to compute, even if they compute a less precise derivative.
The upshot of these considerations is that the optimal choice of derivatives is likely to be quite dependent on the precise variant of Datalog being evaluated, and the specifics of the evaluation engine. Here is one possibility, which is the one used at Semmle.

A concrete Datalog formula derivative.
In fig. 2, we define a "symbolic" derivative operator as a pair of mutually recursive functions, ∆ and ∇, which turn a Datalog formula T into new formulae that compute the upwards and downwards parts of the derivative, respectively. Our definition uses an auxiliary function, X, which computes the "neXt" value of a term by applying the upwards and Then ∆(T ) and ∇(T ) are disjoint, and for any schema Γ and any Datalog formula T whose free term variables are contained in Γ,

Examples.
We can now give a derivative for our treeP predicate by mechanically applying the recursive functions defined in fig. 2. This derivative is composed of an upward part ∆(treeP(x)) and a downward part ∇(treeP(x)).
∧ ∆(treeP(y))) ∧ ¬∃y.(child(x, y) ∧ ¬X(treeP(y))) 11 While the definitions usually exhibit the dualities we would expect between corresponding operators, there are a few asymmetries to explain. The asymmetry between the cases for ∆(T ∨ U ) and ∇(T ∧ U ) is for operational reasons. The symmetrical version of ∆(T ∨ U ) is (∆(T ) ∧ ¬U ) ∨ (∆(U ) ∧ ¬T ) (which is also precise). The reason we omit the negated conjuncts is simply that they are costly to compute and not especially helpful to our evaluation engine. The asymmetry between the cases for ∃ is because our dialect of Datalog does not have a primitive universal quantifier. If we did have one, the cases for ∃ would be dual to the corresponding cases for ∀.
The upwards difference in particular is not especially easy to compute. If we naively compute it, the third conjunct requires us to recompute the whole of the recursive part. However, the second conjunct gives us a guard: we only need to evaluate the third conjunct if the second conjunct is non-empty, i.e there is some change in the body of the existential.
This shows that our derivatives aren't a panacea: it is simply hard to compute downwards differences for ∃ (and, equivalently, upwards differences for ∀) because we must check that there is no other way of deriving the same facts. 12 However, we can still avoid the re-evaluation in many cases, and the inefficiency is local to this subformula.

Precision.
In practice, while the derivative given in theorem 27 is not precise, most of the cases are preciseness-preserving, in that if the subsidiary recursive cases are precise, then so is that case. The only cases which lose precision are labelled with †.

Extensions to Datalog
Our formulation of Datalog formula semantics and derivatives is generic and modular, so it is easy to extend the language with new formula constructs: all we need to do is add cases for ∆ and ∇.
In fact, because we are using a complete change action, we can always do this by using the maximal or minimal derivative. This justifies our claim that we can support arbitrary additional formula constructs: although the maximal and minimal derivatives are likely to be impractical, having them available as options means that we will never be completely stymied. This is important in practice: here is a real example from Semmle's variant of Datalog. This includes a kind of aggregates which have well-defined recursive semantics. Aggregates have the form where agg refers to an aggregation function (such as "sum" or "min"), vs is a sequence of variables, p and r are variables, T is a formula possibly mentioning vs, and U is a formula possibly mentioning vs and p. The full details can been found in de Moor and Baars [17], but for example this allows us to write which recursively computes the height of a node in a tree.
Here is an upwards derivative for an aggregate formula: 12 The "support" data structures introduced by [23] are an attempt to avoid this issue by tracking the number of derivations of each tuple.
While this isn't a precise derivative, it is still substantially cheaper than re-evaluating the whole subformula, as the first conjunct acts as a guard, allowing us to skip the second conjunct when U has not changed.

CHANGES ON FUNCTIONS
So far we have found change actions for spaces that are a good representation of simple data, but we would also like to have change actions on function spaces. This would enable us to have derivatives for higher-order languages, and in particular derivatives for fixpoint operators fix : (A → A) → A, which are higher-order functions.
Function spaces, however, differ from products and disjoint unions in that, given change actionŝ A andB, there is no obvious choice of a "best" change action structure on A → B. Instead of settling on a concrete choice of a change action, we will instead pick out subsets of "well-behaved" change actions on function spaces.
Definition 28 (Functional Change Action). Given change actionsÂ andB and a set U ⊆ A → B, a change actionÛ = (U , ∆U , ⊕ U ) is functional whenever the evaluation map ev : U × A → B is differentiable, that is to say, whenever there exists a function ev ′ : a), (δ f , δa)) We will writeÛ ⊆Â ⇒B whenever U ⊆ A → B andÛ is functional.
We have defined functional change actions on arbitrary subsets U ⊆ A → B for two reasons. First, it will later allow us to restrict ourselves to spaces of monotone or continuous functions. But more importantly, functional change actions are necessarily made up of differentiable functions, and thus a functional change action may not exist for the entire function space A → B.
Proposition 29. LetÛ ⊆Â ⇒B be a functional change action. Then every f ∈ U is differentiable, with a derivative f ′ given by:

Pointwise functional change actions
It is, in general, hard to find functional change actions on the set of differentiable functionsÂ →B. Fortunately, in many important cases there is a simple change action structure on the space of differentiable functions.
Definition 30 (Pointwise functional change action). LetÂ andB be change actions. The pointwise functional change actionÂ ⇒ ptB , when it is defined, is given by (Â →B, A → ∆B, ⊕ → ), with the monoid structure (A → ∆B, · → , 0 → ) and the action ⊕ → defined by: The above definition isn't always well-typed, since given f :Â →B and δ f : A → ∆B there is, in general, no guarantee that f ⊕ → δ f is differentiable. We present two simple criteria that guarantee this.
Theorem 31. LetÂ andB be change actions, and suppose thatB satisfies one of the following conditions: •B is a complete change action. Then the pointwise functional change action (Â →B, A → ∆B, ⊕ → ) is well defined. 13 As a direct consequence of this, it follows that whenever L is a Boolean algebra, the pointwise functional change actionÂ ⇒ ptL▷◁ is well-defined.
Pointwise functional change actions are functional in the sense of definition 28. Moreover, the derivative of the evaluation map is quite easy to compute.
Proposition 32 (Derivatives of the evaluation map). LetÂ andB be change actions such that the pointwise functional change actionÂ ⇒ ptB is well defined, and let f :Â →B, a ∈ A, δa ∈ ∆A, δ f ∈ A → ∆B.
Then, by taking a derivative of f we obtain the following derivative for the evaluation map: Alternatively, by taking a derivative of f ⊕δ f we can obtain another derivative for the evaluation map: a), (δ f , δa)) δ f (a) · (f ⊕ δ f ) ′ (a, δa) Having pointwise function changes allows us to actually compute a derivative of the evaluation map as shown. In practice, this means that we will only be able to use the results in section 6.2 (incremental computation and derivatives of fixpoints) when we have pointwise change actions, or where we have some other way of computing a derivative of the evaluation map.

DIRECTED-COMPLETE PARTIAL ORDERS AND FIXPOINTS
Directed-complete partial orders (dcpos) equipped with a least element, are an important class of posets. They provide us with the ability to take fixpoints of (Scott-)continuous maps, which is especially important for interpreting recursion in program semantics.

Dcpos
As before, we can define change actions on dcpos, rather than sets, as change actions whose base and change sets are endowed with a dcpo structure, and where the monoid operation and action are continuous. Definition 33. A change actionÂ is continuous if • A and ∆A are dcpos.
• ⊕ is Scott-continuous as a map from A × ∆A → A.
• · is Scott-continuous as a map from ∆A × ∆A → ∆A.
Unlike the case for posets, the change order ≤ ∆ does not, in general, induce a dcpo on ∆A. As a counterexample, consider the change action (N, N, +), where N denotes the dcpo of natural numbers extended with positive infinity.
A key example of a continuous change action is theL ▷◁ change action on Boolean algebras.
Proposition 34 (Boolean algebra continuity). Let L be a Boolean algebra. ThenL ▷◁ is a continuous change action.
For a general overview of results in domain theory and dcpos, we refer the reader to an introductory work such as [2], but we state here some specific results that we shall be using, such as the following, whose proof can be found in [2, Lemma 3.2.6]: 13 Either of these conditions is enough to guarantee that the pointwise functional change action is well defined, but it can be the case thatB satisfies neither and yet pointwise change actions intoB do exist. A precise account of when pointwise functional change actions exist is outside the scope of this paper.
It is a well-known result in standard calculus that the limit of an absolutely convergent sequence of differentiable functions { f i } is itself differentiable, and its derivative is equal to the limit of the derivatives of the f i . A remarkable consequence of the previous distributivity property is the following analogous result: We also state the following additional fixpoint lemma. This is a specialization of Bekić's Theorem [41, section 10.1], but it has a straightforward direct proof.

Fixpoints
Fixpoints appear frequently in the semantics of languages with recursion. If we can give a generic account of how to compute fixpoints using change actions, then this gives us a compositional way of extending a derivative for the non-recursive semantics of a language to a derivative that can also handle recursion. We will later apply this to full recursive Datalog (section 7.2).

Iteration functions.
Over directed-complete partial orders we can define a least fixpoint operator lfp in terms of the iteration function iter: The iteration function is the basis for all the results in this section: we can take a partial derivative with respect to n, and this will give us a way to get to the next iteration incrementally; and we can take the partial derivative with respect to f , and this will give us a way to get from iterating f to iterating f ⊕ δ f .

Incremental computation of fixpoints.
The following theorems provide a generalization of semi-naive evaluation to any differentiable function over a continuous change action. Throughout this section we will assume that we have a continuous change actionÂ, and any reference to the change actionN will refer to the obvious monoidal change action on the naturals defined in section 2.1.1.
Since we are trying to incrementalize the iterative step, we start by taking the partial derivative of iter with respect to n.

Fixing incremental computation 1:17
Proposition 38 (Derivative of the iteration map with respect to n). LetÂ be a complete change action and let f : A → A be a differentiable function. Then iter is differentiable with respect to its second argument, and a partial derivative is given by: By using the following recurrence relation, we can then compute ∂ 2 iter along with iter simultaneously: Which has the property that This gives us a way to compute a fixpoint incrementally, by adding successive changes to an accumulator until we reach it. This is exactly how semi-naive evaluation works, with the delta relation and the accumulator relation.
Theorem 39 (Incremental computation of least fixpoints). LetÂ be a complete, continuous change action, f :Â →Â be continuous and differentiable.

Derivatives of fixpoints.
In the previous section we have shown how to use derivatives to compute fixpoints more efficiently, but we also want to take the derivative of the fixpoint operator itself. A typical use case for this is where we have calculated some fixpoint F E fix(λX .F (E, X )) then update the parameter E with some change δE and wish to compute the new value of the fixpoint, i.e.
i.e. we are applying a change to the function whose fixpoint we are taking. In Datalog this would allow us to update a recursively defined relation given an update to one of its non-recursive dependencies, or the extensional database. For example, we might want to take the transitive closure relation and update it by changing the edge relation e. 15 However, this requires us to provide a derivative for the fixpoint operator fix with respect to the function whose fixpoint is being taken.
Definition 40 (Derivatives of fixpoints). LetÂ be a change action, letÛ ⊆Â ⇒Â be a functional change action (not necessarily pointwise) and suppose fix U and fix ∆A are fixpoint operators for endofunctions on U and ∆A respectively.
The suggestively named fix ′ U will in fact turn out to be a derivative -for least fixpoints. The appearance of ev ′ , a derivative of the evaluation map, in the definition of adjust is also no coincidence: as evaluating a fixpoint consists of many steps of applying the evaluation map, so computing the derivative of a fixpoint consists of many stages of applying the derivative of the evaluation map. 16 Theorem 41 (Pseudo-derivatives of fixpoints). LetÂ be a change action,Û ⊆Â ⇒Â be a functional change action, fix U , and fix ∆A be as in definition 40. Then, for any differentiable function f ∈ U and This is not enough to give us a true derivative, because we have only shown that fix U (f ) ⊕ fix ′ U (f , δ f ) computes a fixpoint for f ⊕ δ f , but not necessarily the same one computed by fix U (f ⊕ δ f ).
However, if we restrict ourselves to directed-complete partial orders, least fixpoints, and continuous change actions, then lfp ′ (using the derivative defined for fixpoint operators in definition 40) is a derivative of lfp. This is not too onerous a restriction, since this is a very natural setting for computing fixpoints.
Since lfp is characterized as the limit of a chain of functions, corollary 36 suggests a way to compute its derivative. It suffices to find a derivative iter ′ n of each iteration map such that the resulting set {iter ′ n | n ∈ N} is directed, which will entail that n ∈N iter ′ n is a derivative of lfp. These correspond to the first partial derivative of iter -this time with respect to f . While we are differentiating with respect to f , we are still going to need to define our derivatives inductively in terms of n.
Proposition 42 (Derivative of the iteration map with respect to f ). iter is differentiable with respect to its first argument and a derivative is given by: As before, we can now compute ∂ 1 iter together with iter by mutual recursion. 17 recur a), (δ f , δa))) Which has the property that δ f , n)).
This indeed provides us with a function whose limit we can take, showing that lfp ′ is a true derivative. 16 Perhaps surprisingly, the authors first discovered an expanded version of this formula, and it was only later that we realised the remarkable connection to ev ′ . 17 In fact, the recursion here is not mutual: the first component does not depend on the second. However, writing it in this way makes it amenable to computation by fixpoint, and we will in fact be able to avoid the recomputation of iter n when we show that it is equivalent to lfp ′ .

Fixing incremental computation 1:19
Theorem 43 (Derivatives of least fixpoint operators). Let •Â be a continuous change action • U be the set of continuous functions f : A → A, with a functional change actionÛ ⊆Â ⇒Â • f ∈ U be a continuous, differentiable function • δ f ∈ ∆U be a function change • ev ′ be a derivative of the evaluation map which is continuous with respect to a and δa. Then lfp ′ is a derivative of lfp.
Computing this derivative still requires computing a fixpoint -over the change lattice -but this may still be significantly less expensive than recomputing the full new fixpoint.

DERIVATIVES FOR RECURSIVE DATALOG
Given the non-recursive semantics for a language, we can extend it to handle recursive definitions using fixpoints. Section 6.2 lets us extend our derivative for the non-recursive semantics to a derivative for the recursive semantics, as well as letting us compute the fixpoints themselves incrementally.
Again, we will demonstrate the technique with Datalog, although the approach is generic.

Semantics of Datalog programs
First of all, we define the usual "immediate consequence operator" which computes "one step" of our program semantics.
Definition 44. Given a program P = (P 1 , . . . , P n ), where P i is a predicate, with schema Γ i , the immediate consequence operator I : Rel n → Rel n is defined as follows: That is, given a value for the program, we pass in all the relations to the denotation of each predicate, to get a new tuple of relations.
Definition 45. The semantics of a program P is defined to be P lfp Rel n (I) and may be calculated by iterative application of I to ⊥ until fixpoint is reached.
Whether or not this program semantics exists will depend on whether the fixpoint exists. Typically this is ensured by constraining the program such that I is monotone (or, in the context of a dcpo, continuous). We do not require monotonicity to apply theorem 39 (and hence we can incrementally compute fixpoints that happen to exist even though the generating function is not monotonic), but it is required to apply theorem 43.

Incremental evaluation of Datalog
We can easily extend a derivative for the formula semantics to a derivative for the immediate consequence operator I. Putting this together with the results from section 6.2, we get our two big results.
Corollary 46. Datalog program semantics can be evaluated incrementally. This is known (semi-naive evaluation), but our proof is more modular, so we will be able to extend this result more easily.
Corollary 47. Datalog program semantics can be incrementally maintained with changes to extensional (EDB) relations. This is known [see 23, and successors], but again, the proof is now modular so we can extend it. 7.2.1 Worked example of updating a recursive Datalog program. The algorithm in theorem 43 is very abstract, and it is hard to see how it will work out in practice. It is therefore worth doing a simple worked example.
Consider the tc program from section 1: tc(x, y) ← e(x, y) ∨ ∃z.(e(x, z) ∧ tc(z, y)) We will start with an edge relation e 1 and change it to a new edge relation e 2 by applying a change δe, which both adds and removes some values. We want to update the fixpoint of tc using e 1 , which we will call tc e 1 , to the fixpoint of tc using e 2 , which we will call tc e 2 . As we have seen in theorem 43, we can do this by computing the fixpoint δw = lfp(adjust(tc e 1 , δtc)).
A reminder of the expanded definition of adjust: We've chosen the second definition of ev from proposition 32, since we already know what f ⊕ δ f looks like -it is simply tc e 2 -and δtc(lfp(tc e 1 )) can be computed once up front and reused throughout the computation.

EMPIRICAL EVALUATION
The necessity of semi-naive evaluation for practical Datalog engines is well-established, as we have seen, it can lead to asymptotic improvements. One might ask whether we actually gain anything by further expanding the set of predicates which we can evaluate incrementally -what if we just evaluated the predicates that we can evaluate with semi-naive with semi-naive, and evaluated the other predicates naively? If the non-semi-naive predicates are rare enough, then perhaps this will not matter.
We tested this empirically using Semmle's commercial Datalog engine, which uses exactly the derivatives described in fig. 2. We used two versions of the engine: • A "full" version using the incremental evaluation strategy described in this paper • A "semi-naive" version which evaluates predicates using traditional semi-naive evaluation, falling back to naive evaluation when it cannot be applied.
We used Semmle's profiling infrastructure, which runs over 800 queries (compiled to Datalog programs) on a wide range of real-world databases. The queries are compiled from Semmle's QL language [5], which produces large Datalog programs -a typical size is over 30,000 lines of Datalog. The databases represent real-world programs that are subject to analysis, for example the Linux kernel, which is 1.8 MLOC and produces a database of size 783Mb.
The profiler runs each query on each database with each version of the compiler Queries are run with a (generous) timeout -as we will see, many of the queries will in fact time out.
Comparing the results for the two incrementalization strategies gives the following high-level picture:

Statistic Value
Total runs 2308 Runs which time out in "semi-naive" but not in "full" 629 (27% of all runs) Runs which take more time to evaluate in "semi-naive" than "full" 1049 (45% of all runs) Runs which take less time to evaluate in "semi-naive" than "full" 630 (27% of all runs) This presents a somewhat inconsistent outcome, with some queries improving and some regressing. However, the most interesting category is the category of timeouts that appear in "semi-naive" but not in "full". Further investigation reveals that these regress very badly indeed. For many of these query/database pairs, the authors have been unable to allocate enough memory and time for the query to actually complete. Ad hoc investigation reveals that many of those have a similar evaluation pattern to the tc example in section 1 -where there is a very long chain of deductions needed to fully evaluate the predicate. In this case naive evaluation will scan the entire accumulator predicate in every iteration, leading to quadratic runtime.
This shows us more-or-less what we expected: for many queries the results are moderate and broadly positive, but for some queries incremental evaluation is essential for evaluation to be feasible at all.
We have not performed evaluation of different variants of fig. 2 against each other. Changes to the precise form of the derivative are important, but mostly a matter of adapting them to the particular database engine, and so of less general interest. 9 RELATED WORK 9.1 Change actions and incremental computation 9.1.1 Change structures. The seminal paper in this area is Cai et al. [12]. We deviate from that excellent paper in three regards: the inclusion of minus operators, the nature of function changes, and the use of dependent types.
We have omitted minus operators from our definition because there are many interesting change actions that are not complete and so cannot have a minus operator. Where we can find a change structure with a minus operator, often we are forced to use unwieldy representations for change sets, and Cai et al. cite this as their reason for using a dependent type of changes. For example, the monoidal change actions on sets and lists are clearly useful for incremental computation on streams, yet they do not admit minus operators -instead, one would be forced to work with e.g. multisets admitting negative arities, as Cai et al. do.
Our function changes (when well behaved) correspond to what Cai et al. call pointwise differences [see 12, section 2.2]. As they point out, you can reconstruct their function changes from pointwise changes and derivatives, so the two formulations are equivalent.
The equivalence of our presentations means that our work should be compatible with ILC [see 12, section 3]. The derivatives we give in section 4.2 are more or less a "change semantics" for Datalog [see 12, section 3.5].
9.1.2 S-acts. S-acts (i.e the category of monoid actions on sets) and their categorical structure have received a fair amount of attention over the years (Kilp et al. [28] is a good overview). However, there is a key difference between change actions considered as a category (CAct) and the category of S-acts SAct: the objects of SAct all maintain the same monoid structure, whereas we are interested in changing both the base set and the structure of the action.
There are similarities: if we compare the definition of an "act-preserving" homeomorphism in SAct [see 28] we can see that the structure is quite similar to the definition of differentiability: That is, we use f ′ to transform the action element into the new monoid, whereas in SAct it simply remains the same. In fact, SAct is a subcategory of CAct, where we only consider change actions with change set S, and the only functions are those whose derivative is λa.λd.d. [3] gives a derivative operator for fixpoints based on the framework in Cai et al. [12]. However, since we have different notions of function changes, the result is inapplicable as stated. In addition, we require a somewhat different set of conditions; in particular, we don't require our changes to always be increasing.

Datalog
9.2.1 Incremental evaluation. The earliest interpretation of semi-naive evaluation as a derivative appears in Bancilhon [6]. The idea of using an approximate derivative and the requisite soundness condition appears as a throwaway comment in Bancilhon and Ramakrishnan [7, section 3.2.2], and it would appear that nobody has since developed that approach.
As far as we know, traditional semi-naive is the state of the art in incremental, bottom-up, Datalog evaluation, and there are no strategies that accommodate additional language features such as parity-stratified negation and aggregates.

Incremental maintenance.
There is existing literature on incremental maintenance of relational algebra expressions. In particular Griffin et al. [22] following Qian and Wiederhold [32] reveal the essential insight that it is necessary to track both an "upwards" and a "downwards" difference, and produce a set of rules that look quite similar to those we derive in theorem 27.
Where our presentation improves over Griffin et al. is mainly in the genericity of the presentation. Our machinery works for a wider variety of algebraic structures, and it is clear how the parts of the proof work together to produce the result. In addition, it is easy to see how to extend the proofs to cover additional language constructs.
There are some inessential points of difference as well: we work on Datalog, rather than relational algebra; and we use set semantics rather than bag semantics. This is largely a matter of convenience: Datalog is an easier language to work with, and set semantics allows a much wider range of valid simplifications. However, all the same machinery applies to relational algebra with bag semantics, it is simply necessary to produce a valid version of theorem 27. Since bag semantics also has a complete change action (using multisets), we can always do this.
We also solve the problem of updating recursive expressions. As far as we know, this is unsolved in general. Most of the attempts to solve it have focussed on Datalog rather than relational algebra, since Datalog is designed to make heavy use of recursion.
Several approaches [23,25], most notably DReD make use of a common tactic: one can get to the new fixed point by starting from any point below it, and then iterating the semantics again to fixpoint. The approach, then, is to find a way to delete as few facts as possible to get below the new fixpoint, and then iterate again (possibly using an incremental version of the semantics). This is a perfectly reasonable approach, and given a good, domain-specific, means of getting below the fixpoint, they can be quite efficient. The main defect of these approaches is that they are domain specific, and hence inflexible with respect to changes in the language or structure, whereas our approach is quite generic. Although we know of no theoretical reason why either approach should give superior performance when both are applicable, an empirical investigation of this could prove interesting.
Other approaches [18,40] consider only restricted subsets of Datalog, or incur other substantial constraints, and our results are thus significantly more general. [4]) is a functional programming language that embeds Datalog, allowing significant improvements in genericity, such as the use of higher-order functions. Since we have directly defined a change action and derivative operator for Datalog, our work could be used as a "plugin" in the sense of Cai et al., allowing Datafun to compute its internal fixpoints incrementally, but also allowing Datafun expressions to be fully incrementally maintained.

Embedding Datalog. Datafun (Arntzenius and Krishnaswami
In a different direction, Cathcart Burn et al. [13] have proposed higher-order constrained Horn clauses (HoCHC), a new class of constraints for the automatic verification of higher-order programs. HoCHC may be viewed as a higher-order extension of Datalog. Change actions can be readily applied to organise an efficient semi-naive method for solving HoCHC systems.

Differential λ-calculus
Another setting where derivatives of arbitrary higher-order programs have been studied is the differential λ-calculus [19,20]. This is a higher-order, simply-typed λ-calculus which allows for computing the derivative of a function, in a similar way to the notion of derivative in Cai's work and the present paper.
While there are clear similarities between the two systems, the most important difference is the properties of the derivatives themselves: in the differential λ-calculus, derivatives are guaranteed to be linear in their second argument, whereas in our approach derivatives do not have this restriction but are instead required to satisfy a strong relation to the function that is being differentiated (see definition 2).
Families of denotational models for the differential λ-calculus have been studied in depth [10,11,14,27], and the relationship between these and change actions is the subject of ongoing work.

Higher-order automatic differentiation
Automatic differentiation [21] is a technique that allows for efficiently computing the derivative of arbitrary programs, with applications in probabilistic modeling [29] and machine learning [8] among other areas. In recent times, this technique has been successfully applied to higher-order languages [9,38]. While some approaches have been suggested [26,31], a general theoretical framework for this technique is still a matter of open research.
To this purpose, some authors have proposed the incremental λ-calculus as a foundational framework on which models of automatic differentiation can be based [26]. We believe our change actions are better suited to this purpose than the incremental λ-calculus, since one can easily give them a synthetic differential geometric reading (by interpretingÂ as an Euclidean module and ∆A as its corresponding spectrum, for example).

FUTURE WORK
Our work opens a number of avenues for future investigation.

The category of change actions
First, there is a category CAct of change actions and differentiable functions between them, since the identity function is differentiable and the chain rule guarantees that composition preserves differentiability. The product and sum change actions described in section section 2.3.3 correspond to products and coproducts in this category. Furthermore, theorem 31 can be read as showing that complete change actions form an exponential ideal in CAct.
A simple result shows that the category CAct is remarkably well-behaved: Theorem 10.1. The category CAct is equivalent to the category PreOrd of preorders and monotone functions.
This has the consequence that CAct is Cartesian closed. This result, however, isn't very helpful in practice as the resulting exponentials in CAct are not computable. A more thorough study of the category CAct could lead to a presentation of exponentials that is more suitable to actual computation.
Fortunately, under some circumstances exponential objects in CAct correspond to the pointwise functional change actions we defined earlier (in section 5.1).
Definition 48. A change actionB is convenient if every exponential objectÂ ⇒B is isomorphic to a pointwise functional change action.

Fixing incremental computation 1:25
Fortunately, convenient change actions form a relatively large subcategory of CAct. In particular, complete change actions are convenient.
Since the product and exponential of complete change actions are also complete, the complete change actions are a Cartesian closed full subcategory of CAct which is, in fact equivalent to Set (as every set-theoretic function between complete change actions is differentiable). Furthermore, it can be shown that the product and exponential of two convenient change actions are in turn convenient change actions, and hence convenient change actions are themselves a Cartesian closed subcategory of CAct. We believe these can therefore provide a suitable model for general higher-order incremental computation in the future.
These preliminary results all suggest that the category CAct is an interesting subject of study in itself. Many important questions, especially with respect to the structure of exponentials and the existence of limits and colimits remain unsettled.

Change actions as 2-categories
There is an interesting connection between the category CAct and the 2-category Cat of categories and functors: given a change actionÂ one can consider the category that has elements of A as objects and a morphism f δ a : a → b for every change δa ∈ ∆A such that a ⊕ δa = b. If one requires that derivatives verify the additional conditions in the footnote to definition 2, then functions that admit derivatives correspond exactly to functors. This naturally leads to consider dependentlytyped generalizations of change actions where different elements a, b ∈ A have different change sets ∆ a A, ∆ a B, much like in Cai et al.'s original presentation.

Change actions on arbitrary categories
A more abstract approach is also possible: throughout this work we have restricted ourselves to change actions defined over the category of sets, but most of the definitions and results presented here could be easily generalized to any category with products. The resulting theory is the subject of ongoing work by the authors.
Of those, the theory of change actions on the category of domains is of particular interest to us. Since domains are used to model programming language semantics in the presence of general recursion, a theory of change actions on the category of domains could open up opportunities for incremental evaluation of many programming languages, even those that do not fit into the model of Cai et al.'s ILC. Our fixpoint theorems are proven over dcpos in general, and we believe these to be a crucial first step into a more general theory of a hypothetical incremental extension to PCF.
Additionally, we have only begun to explore the tantalizing connection between change actions, the ILC and synthetic differential geometry, and a denotational semantics for the ILC based on smooth spaces is the subject of ongoing research. We believe many concepts from standard differential geometry, like gradients, vector fields, curves and flows can be defined in general on change actions, which could lead to developments in differentiable programming languages.
Finally, combining our concrete Datalog derivatives with a system similar to ILC in a language such as Datafun would be an exciting demonstration of the compositional power of this approach.

CONCLUSIONS
We have presented change actions and their properties, and used them to provide novel, compositional, strategies for incrementally evaluating and maintaining recursive functions, in particular the semantics of Datalog. ThenÂ ×B (A × B, ∆A × ∆B, ⊕ × ) is a change action, where ⊕ × is defined by: The projection maps π 1 ,π 2 are differentiable with respect to it. Furthermore, a function f : A × B → C is differentiable fromÂ ×B intoĈ if and only if, for every fixed a ∈ A and b ∈ B, the partially applied functions f (a, ·) : Proof. LetŶ be a change action, and f 1 :Ŷ →Â, f 2 :Ŷ →B be morphisms. Then the product morphism in Set, ⟨f 1 , f 2 ⟩ is the product morphism in CAct. It can easily be shown that f ′ 1 , f ′ 2 is a derivative of ⟨f 1 , f 2 ⟩, hence ⟨f 1 , f 2 ⟩ is a morphism in SAct. Commutativity and uniqueness follow from the corresponding properties of the product in the Set.
The injection maps ι 1 , ι 2 are differentiable with respect toÂ +B. Furthermore, wheneverĈ is a change action and f : A → C, д : B → C are differentiable, then so is [f , д].
Proof. LetŶ be a change action, and f 1 :Â →Ŷ , f 2 :B →Ŷ be differentiable functions. As before, it suffices to prove that the universal function [f 1 , f 2 ] in Set is a differentiable function from (A + B, ∆A × ∆B, ⊕ A+B ) into Y . It's easy to see that the following morphism is a derivative:
ThenL ▷◁ is a complete change action on L.
Completeness is easy to show. □ Proposition 23 (Boolean algebra kernels). Let L be a (complete) Boolean algebra with theL ▷◁ change action, f :Â →L a (differentiable) function, and suppose f ′ 1 and f ′ 2 are derivatives for f . Then f ′ 1 ≤ ∼ f ′ 2 (extending the kernel order pointwise to derivatives) iff for all a ∈ A and δa ∈ ∆A f ′ 1 (a, δa) ≤ pt f ′ 2 (a, δa) Additionally, the following is a minus operator, and f ′ ⊖ ∼ is a minimal derivative with respect to ≤ pt and ≤ ∼ : Proof. First we show that for any p, q, r , s ∈ L, p ≤ r and q ≤ s implies (p, q) ≤ ∼ (r , s). We note that the condition implies (p, q) · ▷◁ (r , s) = ((p ∧ ¬s) ∨ r , (q ∧ ¬r ) ∨ s) Hence ∼ (p,q) ⊆∼ (r,s) , so (p, q) ≤ ∼ (r , s). The "only if" part of the proposition follows trivially from this.
To see that this is the case, we note that

≤ ¬s
Hence p ∧ s ≤ ¬s, therefore p ∧ s = ⊥, which concludes the proof that p ≤ r . The proof that q ≤ s is symmetric. □

A.3 Derivatives of Datalog formulae
Theorem 27 (Concrete Datalog formula derivatives). Let ∆, ∇, X : Formula → Formula be mutually recursive functions defined by structural induction as in fig. 2. Then ∆(T ) and ∇(T ) are disjoint, and for any schema Γ and any Datalog formula T whose free term variables are contained in Γ, Proof. Let T be a Datalog formula with free relation variables R 1 , . . . , R n , a choice of a semantics for the free relation variables R 1 , . . . , R n ∈ Rel Γ and differences δ R 1 , . . . , δ R n ∈ Rel Γ ▷◁ Rel Γ .
For brevity, we refer to the tuple (R 1 , . . . , R n ) as R and the tuple (δ R 1 , . . . , δ R n ) as δ R. We abuse the notation and refer to (R 1 ⊕ ▷◁ δ R 1 , . . . , R n ⊕ ▷◁ δ R n ) as R ⊕ ▷◁ δ R. We will also omit the arguments to ∆T and ∇T often, as there is never room for ambiguity.
Then, it is the case that We proceed by structural induction on T . We omit the cases for ⊤, ⊥ and relational variables for being trivial.

A.4 Directed-complete partial orders and fixpoints
Proposition 34 (Boolean algebra continuity). Let L be a Boolean algebra. ThenL ▷◁ is a continuous change action.
Proof. L is a complete lattice, so certainly a dcpo.L ▷◁ is a dcpo with (p i , q i ) ( p i ∧ ¬ q i , q i ).

1:32
Mario Alvarez Picallo, Alex Eyers-Taylor, Michael Peyton Jones, and C.-H. Luke Ong Continuity of ⊕ ▷◁ in its second argument: Then h(h i (⊥)) ≤ p(p i (⊥)) (by simple induction), and so by continuity But h(lfp(p)) = lfp(p), so lfp(h) ≤ lfp(p), since lfp(h) is least. Hence lfp(h) = lfp(p) = (lfp(f ), lfp(λb.д(lfp(f ), b))). □ Proposition 38 (Derivative of the iteration map with respect to n). LetÂ be a complete change action and let f : A → A be a differentiable function. Then iter is differentiable with respect to its second argument, and a partial derivative is given by: Proof. By induction on n. We show the inductive step. Theorem 39 (Incremental computation of least fixpoints). LetÂ be a complete, continuous change action, f :Â →Â be continuous and differentiable.