[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"7Wwo9sJlWB":3},"# autoinc-lean\n\n## Overview\n\n`autoinc-lean` (**Auto**matic **inc**remental computation in **Lean**) is a formal framework for building and reasoning about incremental computation.\n  \nThe main goal of `autoinc-lean` is to investigate methodologies for automatically compiling a standard computation $C$ into an incremental computation $\\Delta C$, such that $\\Delta C$ is asymptotic faster than $C$. \n\nThe strategy of `autoinc-lean` for incrementalizing programs is called *differential updating*, which translates a program's input changes to output changes. \n\n## Installation\n\nThis project is known to compile with Lean v4.27.0-rc1. \nPlease read [this](https://lean-lang.org/install/) website to install lean in your computer.\nAfter that, you may run the following commands to install dependencies and compile this project:\n\n```\n$ lake exe cache get\n$ lake build\n```\n\n\n\nWe have only tested the installation on MacOS, but we expect it to work on Linux and Windows systems as well.\n\n\n## Example\n\nConsider the dataflow of a word-count program \n\n```\ntext.toLowerCase().split(\" \").filter(isNotEmpty).count()\n```\n\n![](\u003CUtils/wordcount.svg>)\n\nTo process input changes (e.g., appending a whitespace), differential updating transforms the above program into the following form, where each primitive `f : A -> B` is replaced by its respective *differential operator* `Δf : ΔA -> ΔB`:\n\n![](\u003CUtils/dwordcount.svg>)\n\nBy exploiting the algebraic properties of data changes and string functions, differential updating derives the output changes in time proportional to the size of the input modification rather than to the total data size.\n\n\nThis repository provides an interface for building and verifying differential operators. \nNotably, this interface is monadic, allowing using various effects to implement expressive operators.\nHere is a differential operator for `List.reverse : List α -> List α`:\n\n```lean4\ndef Δreverse [MonadStateOf Nat m] : Operator (List β) (List β) (ΔList β) (ΔList β) m where\n  f x := do set x.length; pure x.reverse\n  Δf dx := do let s \u003C- get; match dx with\n    | ins i l => set (s + l.length); pure (ins (s - i) l.reverse)\n    | del i n => set (s - n); pure (del (s - i - n) n)\n```\n\nThis operator uses a `Nat` state (the length of original input) to compute the output changes in time proportional to the size of `dx` (input change), which achieves asymptotic speedup over `List.reverse` function.\n\n\n## Project structure\n\n- `./Autoinc.lean`: root of the `Autoinc` library\n- `./Autoinc/Change.lean`: definition of change structure\n- `./Autoinc/Operator.lean`: definition of monadic operators\n- `./Autoinc/Monad.lean`: definition and instances of monadic change structures\n- `./Autoinc/Partial.lean`: definition of partial differential operators (which processes changes a single parameter within an n-ary function)\n- `./Autoinc/Lazy.lean`: definition and laws of lazy state monad \n- `./Autoinc/Combinator.lean`: combinators for differential operators\n- `./Autoinc/Data/*`: change structure and differential operators for different data types\n- `./Benchmark/*`: microbenchmarks for measuring the performance of list differential operators\n  - `./Benchmark/List/Examples/*.lean`: incremental computation built with monadic list differential operators\n  - `./Benchmark/Main.lean`: entry of benchmark, the command to run the benchmark: `lake -q exe benchmark`\n\n\n\n## Contribution\n\nThe development of `autoinc-lean` is lead by the [PL Team](https://pl.ipd.kit.edu/index.php) from KIT under the ERC project \"AutoInc: Asymptotic Speedups for Free through Automatic Incremental Computing\" ([link](https://incremental.dev/)).\nThis repository serves as a snapshot to showcase the current progress, which is why it contains only a single commit. If you are interested, we warmly welcome you to contact the developers. The current contributors are:\n\n- [Sebastian Erdweg](https://github.com/seba--)\n- [Runqing Xu](https://github.com/runqingxu)\n- [Iain Moncrief](https://github.com/iainmon)\n- [Oliver Enes](https://github.com/eneoli)",1780242001762]