-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress-slides.typ
More file actions
242 lines (187 loc) · 7.06 KB
/
progress-slides.typ
File metadata and controls
242 lines (187 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#import "@preview/diatypst:0.9.1": *
#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge
#import "@preview/codly:1.3.0": *
#import "@preview/codly-languages:0.1.8": *
#show: slides.with(
title: "Efficient Coinductives through State-Machine Corecursors",
subtitle: "Optimising the terminal F-coalgebra in Set\nfor computational behaviour in Lean4",
date: "2025-02-23",
authors: ("William Sørensen"),
toc : false,
// title-color: rgb("#DD3025") // Cambridge scarlet
count: "dot-section"
)
#show raw: set text(font : "FiraCode Nerd Font")
#show: codly-init.with()
#codly(languages: codly-languages)
#set heading(numbering: (.., last) => "")
== Polynomials (background)
- A head $H$,
- child families $c_h$ in $h : H$.
- Morally, a collection of constructors $H$,
and data at each constructor $c_h$.
- For now we will not consider "recursive" (inductive) data structures,
rather I will have this be a variable we take the fix point in.
- Examples:
- natural numbers `NatF(X) := 1 + X`,
- lists `ListF(A, X) := 1 + A * X`,
- streams `StreamF(A, X) := A * X`.
$ (h : H) times c_h arrow.r alpha eq.triple sum_(h : H) alpha^(c_h) $
#v(1fr)
See @nlab:polynomial_functor and @atfp
== Coinductives (background)
- Unbounded tree of data.
- Greatest cofixpoint of a polynomial.
- Morally, the process of putting the word "lazy" in front of a functor,
- on lists it sends them to lazy lists.
- Have a corecursion principle rather than an recursion principle,
- instead of `rec : (f a -> a) -> fix f -> a`,
- we have `corec : (a -> f a) -> a -> cofix f`.
- On our examples and their correspondences,
- `cofix NatF`, natural numbers union infinity,
- `cofix ListF(A)`, lists of `A`s with arbitrary length union streams of `A`,
- `cofix StreamF(A)`, infinite streams of `A`s.
#v(1fr)
See @avigad_et_al
== Performance of coinductives (core)
- Previous work has demonstrated implementation of coinductives.
- Computational behaviour was not a concern.
#figure(
image(
"./data/plot.png",
height: 160pt
),
caption: "Performance of the old, new, and a perfect implementation"
)
== ABI Type (extension)
#columns(2)[
- Given $alpha:"Type"_cal(U)$, $beta:"Type"_cal(V)$ and $"eq" : alpha tilde.eq beta$.
- Univalence gives uniqueness.
- Adds a form of "weak-univalence".
- Allows for a zero cost universe transliteration.
- Symmetric form of `Shrink`.
#v(1fr)
#figure(
text(6pt)[
#diagram(
cell-size: 10mm,
// Top row nodes
node((-1, 1), $alpha$, name : <A1>),
node((1, 3), $alpha$, name : <A2>),
node((1, 1), $"Shrink" alpha beta$, name : <S1>),
node((2, 2), $"Shrink" alpha beta$, name : <S2>),
edge(<A1>, <S1>, $text("mk")$, "->"),
edge(<A2>, <S2>, $text("mk")$, "->"),
edge(<S1>, <A2>, $text("dest")$, "->"),
edge(<A1>, <A2>, $bb(1)_alpha$, "->", label-side : right),
edge(<S1>, <S2>, $bb(1)_("Shrink" alpha beta)$, "->"),
)
],
caption:[Operations on Shrink]
)<shrkops>
#colbreak()
#v(1fr)
#figure(
text(6pt)[
#diagram(
cell-size: 10mm,
// Top row nodes
node((-1, 1), $alpha$, name : <A1>),
node((1, 3), $alpha$, name : <A2>),
node((1, -1), $beta$, name : <B1>),
node((3, 1), $beta$, name : <B2>),
node((1, 1), $"ABI" alpha beta$, name : <S1>),
node((2, 2), $"ABI" alpha beta$, name : <S2>),
edge(<A1>, <B1>, $text("eq")$, "="),
edge(<A2>, <B2>, $text("eq")$, "=", bend : -50deg),
edge(<A1>, <S1>, $text("mkA")$, "->"),
edge(<A2>, <S2>, $text("mkA")$, "->"),
edge(<S1>, <A2>, $text("destA")$, "->"),
edge(<A1>, <A2>, $bb(1)_alpha$, "->", label-side : right),
edge(<B1>, <S1>, $text("mkB")$, "->"),
edge(<B2>, <S2>, $text("mkB")$, "->"),
edge(<S1>, <B2>, $text("destB")$, "->"),
edge(<B1>, <B2>, $bb(1)_beta$, "->"),
edge(<S1>, <S2>, $bb(1)_("ABI" alpha beta)$, "->"),
)
],
caption:[Operations on ABI]
)
]
== Interaction Trees (extension)
- Free monad with non-termination as an effect.
```lean
coinductive ITree
(E : Type u -> Type u) (R : Type v) :=
| tau : ITree E R -> ITree E R
| ret : R -> ITree E R
| vis {A : Type u} (e : E A) (k : A -> ITree E R)
```
- $"ITerm" E$ forms a monad,
- With a method $"trigger" : E V → "ITree" E" "V$,
- and $"iter" : (A -> "ITree" E (A + B)) -> A -> "ITree" E" "B$.
- And an equivalence relation $A approx B$,
- satisfying $A approx B <-> #raw("tau") A approx B$.
== Project statistics
#no-codly[
#text(8pt)[```
❯ nix-shell -p cloc --run "cloc . --exclude-dir=.lake"
100 text files.
92 unique files.
14 files ignored.
github.com/AlDanial/cloc v 2.06 T=0.08 s (1110.8 files/s, 124656.0 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Lean 59 1229 252 6621
Typst 20 332 122 1099
SVG 1 0 0 171
JSON 3 0 0 125
TeX 1 4 0 76
YAML 3 8 7 69
Markdown 2 27 0 68
Python 2 22 18 57
Nix 1 2 0 15
-------------------------------------------------------------------------------
SUM: 92 1624 399 8301
-------------------------------------------------------------------------------
```]
]
(excluding mathlib PRs)
== Conclusion
- Lean now has usable coinductive datastructures,
- core completed,
- success criteria met.
- Lean now has an ITree implementation.
- Further work is being done on topics such as:
- LLVM (VeIR) semantics,
- productivity,
- and CTrees.
== Bibliography
#bibliography("bib.bib", style : "apa")
= Further work
== Futumorphic productivity (extension)
- A futumorphism is a morphism `(c -> f (Free f c)) -> c -> cofix f`,
- a terminating function in the futumorphism is exactly a productive one,
- futumorphisms have a unfold lemma which is very hard to prove.
#v(1fr)
See @fantomorph
== LLVM semantics (extension)
- Tobias Grosser's project VeIR wants formalised semantics,
- for this they want to use an ITree interpreter,
- semantics are detailed in @itree-llvm.
== CTree (extension)
- Another coinductive datastructe,
- has visible and silent non-determinism,
```lean
coinductive
(E B : Type u -> Type u) (R : Type v) :=
| ret : R -> ITree E R
| step : ITree E R -> ITree E R
| guard : ITree E R -> ITree E R
| vis {A : Type u} (e : E A) (k : A -> ITree E R)
| br {A : Type u} (e : B A) (k : A -> ITree E R)
| stuck
```
#v(1fr)
See @ctrees_paper