forked from lecopivo/SciLean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.org
More file actions
310 lines (232 loc) · 14.8 KB
/
Copy pathnotes.org
File metadata and controls
310 lines (232 loc) · 14.8 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
* Goals
** Long Term Goal
- Write finite element code where the energy/action can be written down like on paper and the final cede can be differentiated with respect to almost anything like domain, stiffness parameters, initial conditions etc.
- Support compilation to GPU and CPU.
** Mid term Goal
- Semi-automatic differentiation and optimization tools.
- Inline C++ compiler to write efficient low level code.
- Formalize and wrap OpenVDB, NanoVDB, Houdini, Eigen primitives.
- Node based editor in Houdini.
** Short Term Goal
My first goal is to write couple of simple ODE solvers maybe some simple finite difference solvers. The main things to focus on:
- compare performance to hand written C++ code
- attempt at semi-automatic differentiation of energy/lagrangian
*** TODO Lean Framework
Implement these to in the order to get these examples working:
1. Harmonic Oscilator
2. Pendulum
3. NBody
4. NPendulum in 2D
5. NPendulum in 3D
6. 1D wave equation
7. 2D wave equation
**** Reorganization
***** Mathlib
Everything that will hopefully be in mathlib one day
***** Categories
This contains all categories and basic proof automation in those categories.
- proofs for algebraic operations
- proofs for combinators
- Hom and morphisms
****** Cat - common interface for all categories
****** Lin
****** Smooth
****** Diff
****** Cont
****** Set
****** Inv
****** Others - no immediate plan to do these
- LInv - is it a category?
- RInv - is it a category?
- Difeo - This needs diffeology to have internalized Hom
***** Operators
This contains basic operators proofs about them and simplification identities
****** adjoint
****** sum
****** differential operators
differential, gradient, tangent_map, back_prop
****** limit
****** invert -- basic properties and possible approximations
****** integral -- basic properties and possible approximations
****** ode_solve -- basic properties and possible approximations
**** TODO Categories [/]
- [ ] Implement `IsSmooth` - just duplicate IsDiff and add axiom that differential of smooth is smooth
- [ ] Implement `IsLInv` `IsRInv`
- [ ] experiment with `extends` keyword to chain categories properly and test if `IsInv` can be written just as an extension of `IsLInv` and `IsRInv`
- [ ] Define Hom for categories and pick arrows
- Lin: ⊸ --o \-o
- Smooth: ⟿ ~~> \r~3
- Dif: ⇝ -~> \r~2
- Cont: ↦ --> \r6
- Diffeo: ↭ <~> \lr5
- RInv: ↠ ->> \r23
- LInv: ↪ >-> \r8
- Inv: ↔ <-> \lr
- [ ] internalized combinators
- [ ] extract smooth/linear/... symbol - this will create appropriate morphism
- [ ] modify remove lambda let to work with morphisms
- [ ] Specialized notation =λₛ= for morphisms, maybe also ascii version as =fun (x : X) ~~> (f x)= or =fun (v : V) --o (A v)=
- [ ] Implement =IsCont=
- [ ] Add =IsDiffeo= a category of diffeomorphisms
**** TODO Computations [2/11]
- [ ] add simple algebraic simplification, probably based on this [[https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/New.20attribute.20to.20mark.20theorems][zulip chat]]
- Attempt 1: What the link suggest does not work naively in my case :(
- [X] add =autodiff=, =autograd= tactics
- [X] make =rmlamlet= work in conv mode
- [ ] rewrite =autodiff= and =autograd= to use conv mode
- [ ] add =autodual= tactic
- [ ] fix `remove lambda let` to work properly with `let` such that for loops are correctly abstracted
- [ ] Add basic real functions like =sin, cos, exp= and their derivatives and inverses
- [ ] =Vector T n= fixed sized array of type T
- [ ] =Tensor #[n1, n2, n3]= fast float array to hold data - probably column major
- [ ] =Vec2, Vec3, Vec4= simple fixed size vectors
- [ ] =Mat2, Mat3, Mat4= simple fixed size matrices
**** TODO Solver class [3/9]
- [X] add tactics =solver_check= and =solver_assumtion=
- [X] add tactic =lift_limit=
- [X] rewrite =Impl= based on [[https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Working.20with.20constants/near/256707931][Mario's answer]]
- [ ] add tactic =assume_this=
- [ ] add tactic =check_this=
- [ ] refine =lift_limit=
It should automatically call =assume_this= for assuming lifting of the limit
Based on how lift_limit currently works it should call one iteration of beta-reduction.
- [ ] add tactic =finish_impl= probably just `apply Solver.pure`
- [ ] check computability in =finish_impl=
The approach is probably to replace every free variables in the target expression by their instance of `Inhabited`. For this use =Expr.replaceFVar=
If the target is a function, synthesize all arguments with `Inhabited` and apply them.
Finally I need to figure out how to test if an expression can be evaluated.
- [ ] implement =assemble=
**** TODO Variational calculus [/]
- [ ] Figure out how to deal with adjoint and dual in case of integrals
- [ ] Automatize duality on integrals
**** TODO External Linear algebra [/]
On using external C code: [[https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Style.20for.20using.20external.20code][zulip thread]]
[[https://github.com/leanprover/lean4/tree/66fcfcce3716774dacbd35e1ea0f5c75356df311/tests/compiler/foreign][Example]] on how to use =lean_external_object=
- [ ] do a simple experiment to bind some C/C++ linear solver
look into this [[https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/C.20FFI.20usage][zulip thread]] for info and links
- [ ] try wrapping Thrust vector into [[https://github.com/leanprover/lean4/blob/b742f0005f7d96b94260bf2052fb50526f3d6b06/src/include/lean/lean.h#L282][=lean_external_object=]]
*** TODO Sims [/]
**** TODO Harmonic Oscillator [2/6]
- [X] Lean implementation
- [ ] C++ implementation
- [ ] measure performance and create nice comparison
- [X] Hamiltonian formulation
- [ ] Lagrangian formulation
- [ ] Action formulation
**** TODO Pendulum [0/6]
- [ ] Lean implementation
- [ ] C++ implementation
- [ ] measure performance and create nice comparison
- [ ] Hamiltonian formulation
- [ ] Lagrangian formulation
- [ ] Action formulation
**** TODO N-Body Simulation [0/6]
- [ ] Lean implementation
- [ ] C++ implementation
- [ ] measure performance and create nice comparison
- [ ] Hamiltonian formulation
- [ ] Lagrangian formulation
- [ ] Action formulation
**** TODO N-Pendulum [/]
- [ ] Lean implementation
- [ ] C++ implementation
- [ ] measure performance and create nice comparison
- [ ] Hamiltonian formulation
- [ ] Lagrangian formulation
- [ ] Action formulation
**** TODO 1D Wave Equation on Circle [0/6]
- [ ] Lean implementation
- [ ] C++ implementation
- [ ] measure performance and create nice comparison
- [ ] Hamiltonian formulation
- [ ] Lagrangian formulation
- [ ] Action formulation
**** TODO 2D Wave Equation on Torus [/]
- [ ] Lean implementation
- [ ] C++ implementation
- [ ] measure performance and create nice comparison
- [ ] Hamiltonian formulation
- [ ] Lagrangian formulation
- [ ] Action formulation
** Notes on Lean
- When cursor is places at the end of `repeat rw[thrm]` the goal shows only *one* rewrite as repeat didn't work. This is confusing.
* Links
** Articles
*** Main
- [[https://arxiv.org/abs/2007.08017][λₛ: Computable Semantics for Differentiable Programming with Higher-Order Functions and Datatypes, 2021]]
- [[https://arxiv.org/abs/1910.00935][DiffTaichi: Differentiable Programming for Physical Simulation, 2020]]
- [[https://al3623.github.io/assets/documents/LiuPOPL2022.pdf][Verified Tensor-Program Optimization Via High-Level Scheduling Rewrites, 2022]]
*** Other
- [[https://core.ac.uk/download/pdf/82396223.pdf][The Differential Lambda-Calculus, 2003]]
- [[https://dl.acm.org/doi/10.1145/1330017.1330018][Reverse-mode AD in a functional framework: Lambda the Ultimate Backpropagator, 2008]]
- [[https://arxiv.org/abs/1806.02136][Efficient differentiable programming in a functional array-processing language, 2018]]
- [[https://proceedings.neurips.cc/paper/2018/hash/0a1bf96b7165e962e90cb14648c9462d-Abstract.html][Computing Higher Order Derivatives of Matrix and Tensor Expressions, 2018]] and its [[http://www.matrixcalculus.org/matrixCalculus][web app]]
- [[https://arxiv.org/abs/1804.00746][The Simple Essence of Automatic Differentiation (Extended version), 2018]]
- [[https://arxiv.org/abs/1810.11530][Automatic differentiation in ML: Where we are and where we should be going, 2018]]
- [[https://openreview.net/forum?id=ryxuz9SzDB][The Differentiable Curry, 2019]]
- [[https://arxiv.org/abs/1907.07587][A Differentiable Programming System to Bridge Machine Learning and Scientific Computing, 2019]]
- [[https://arxiv.org/abs/1911.04523][A Simple Differentiable Programming Language, 2020]]
- [[https://arxiv.org/abs/1802.04730][Tensor Comprehensions: Framework-Agnostic High-Performance Machine Learning Abstractions]]
- [[https://doi.org/10.1145/3498710][Provably Correct, Asymptotically Efficient, Higher-Order Reverse-Mode Automatic Differentiation, 2022]]
- [[https://openreview.net/forum?id=SJxJtYkPG][A Language and Compiler View on Differentiable Programming, 2023]]
- [[https://arxiv.org/abs/2212.09801][Denotationally Correct, Purely Functional, Efficient Reverse-mode Automatic Differentiation, 2023]]
- [[https://arxiv.org/abs/2212.10307][Efficient and Sound Differentiable Programming in a Functional Array-Processing Language, 2021]]
*** Math Foundation
- [[https://www.mat.univie.ac.at/~kriegl/Skripten/apbook.pdf][The Convenient Setting of Global Analysis, 2008]]
- [[https://www.ams.org/books/surv/185/surv185-endmatter.pdf][Diffeology, 2013]]
*** Lean
- [[https://arxiv.org/abs/2001.10490][Beyond Notations: Hygienic Macro Expansion for Theorem Proving Languages, 2020]]
- [[https://pp.ipd.kit.edu/uploads/publikationen/demoura21lean4.pdf][The Lean 4 Theorem Prover and Programming Language, 2021]]
- [[https://arxiv.org/abs/1908.05647][Counting Immutable Beans: Reference Counting Optimized for Purely Functional Programming, 2019]]
- [[https://www.microsoft.com/en-us/research/uploads/prod/2020/11/perceus-tr-v1.pdf][Perceus: Garbage Free Reference Counting with Reuse, 2020]]
**** Video
- [[https://www.youtube.com/watch?v=UeGvhfW1v9M][Lean Together 2021: An overview of Lean 4]]
- [[https://www.youtube.com/watch?v=hxQ1vvhYN_U][Lean Together 2021: Metaprogramming in Lean 4]]
*** Categorical Formalism
- [[https://www.sciencedirect.com/science/article/pii/0167642387900207][The categorical abstract machine, 1987]]
- [[http://www.cs.man.ac.uk/~david/categories/book/book.pdf][Computational Category Theory, 1988]]
- [[https://www.springer.com/gp/book/9780817636548][Categorical Combinators, Sequential Algorithms, and Functional Programming, 1993]]
- [[https://www.math.mcgill.ca/rags/difftl/MSCS-Differential_Categories.pdf][Differential categories, 2006]]
- [[https://arxiv.org/abs/1006.3140][A convenient differential category, 2010]]
*** Blog posts
- [[https://ocramz.github.io/haskell/automatic-differentiation/2021/07/19/ad-delcont.html][Purely-functional reverse-mode automatic differentiation with delimited continuations]]
*** Presentations
- [[http://www.math.mcgill.ca/rags/JAC/Poster/poster2-JAC-Apr13-handout-6up.pdf][A categorical description of the essential structure of differential calculus, 2013]]
- [[http://www.appliedcategorytheory.org/wp-content/uploads/2017/09/Jason-Morton-An-approach-to-computational-category-theory.pdf][An approach to computational category theory, 2015]]
- [[https://andrejbauer.github.io/domains-floc-2018/slides/Matthijs-Kammar-Staton.pdf][Diffeological Spaces and Denotational Semantics for Differential Programming, 2018]]
*** others
- [[https://www.linkedin.com/in/david-sankel-94059841][David Sankel]]
A guy writing Reflection TS proposal, but why is he interesting is that he developed some visual functional programming language similar to Houdini as he mentioned in [[https://cppcast.com/david-sankel-reflection-ts/][CppCast]].
** Software
- [[http://hackage.haskell.org/package/subhask][subhask]]
- [[http://hackage.haskell.org/package/linearmap-category][linearmap-category]]
- [[https://github.com/jasonmorton/Cateno][Cateno]]
- [[https://fluxml.ai/Zygote.jl/latest/][Zygote]]
- [[https://github.com/mila-iqia/myia][Myia]]
- [[https://github.com/tum-pbs/PhiFlow][PhiFlow]]
- [[https://github.com/yuanming-hu/difftaichi][DiffTaichi]]
- [[https://halide-lang.org/][Halide]]
- [[https://github.com/dselsam/certigrad][Certigrad]]
- [[http://simit-lang.org/][Simit]]
- [[https://github.com/apple/swift/blob/main/docs/DifferentiableProgramming.md][differentiable programming in Swift]]
- [[https://github.com/psg-mit/smooth][Smooth]]
- [[https://web.archive.org/web/20170924065701/http://www.digi-area.com/Mathematica/atlas/][Atlas 2 for Mathematica]]
- [[https://enzyme.mit.edu/][Enzyme]]
- [[https://github.com/google-research/dex-lang][Dex]]
- [[https://futhark-lang.org/][furthark]]
- [[https://iheartla.github.io/][I❤️LA]]
- [[https://github.com/google/jax][Jax]]
- [[https://github.com/patrick-kidger/diffrax][diffrax]]
- [[https://www.tensorflow.org/probability/oryx][Oryx]]
- [[https://github.com/IBM/FormalML][FormalML]]
- [[https://github.com/DiffSharp/DiffSharp][DiffSharp]]
- [[https://github.com/owlbarn/owl][Owl]]
- [[https://github.com/kztk-m/sparcl][Sparcl]] - partially-invertible computation
*** Vaguely related software
- [[https://github.com/enso-org/enso][Enso]] - hybrid visual & textual programming language
** Some relevant Zulip discussions:
- [[https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Extraction.20replacing.20reals.20with.20float.3F][Extraction replacing reals with float?]]
- [[https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Fast.20inline.20compiler.20for.20numerical.20computing][Fast inline compiler for numerical computing]]
- [[https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Lean4.20and.20multidimensional.20arrays][Lean4 and multidimensional arrays]]
- [[https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Interface.20for.20multi-dimensional.20arrays][Interface for multi-dimensional arrays]]
- [[https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Treating.20.60Float.60.20as.20reals.2C.20inconsistent.3F][Treating `Float` as reals, inconsistent?]]