Tomáš Skřivan
Carnegie Mellon University
Hoskinson Center for Formal Mathematics
9.5.2024
The language of science is mathematics
... and Lean speaks it!
Something interesting has to come out of it!
def update (x v : Array Vec3) :=
v := v + Δt * force x
x := x + Δt * v
(x,v)
+
+
+
def foo (x : R) : R := x^2
def foo_deriv (x : R) : R := 2*x
AD
def foo (x : R) : R := x^2
noncomputable
def foo_deriv (x : R) : R := fderiv R (fun x' => foo x') x 1
noncomputable
def fderiv (f : X → Y) (x : X) : X →L[𝕜] Y :=
if h : ∃ (f' : X →L[𝕜] Y), (fun x' => f x' - f x - f' (x' - x)) =o[𝓝 x] fun x' => x' - x then
choose h
else
0
def foo_deriv (x : R) : R := (fderiv R (fun x' => foo x') x 1) rewrite_by fun_trans
@[fun_trans]
noncomputable
def fderiv (f : X → Y) (x : X) : X →L[𝕜] Y := ...
@[fun_trans]
theorem fderiv_add :
(fderiv K fun x => f x + g x)
=
fun x => fderiv K f x + fderiv K g x := ...
@[fun_trans]
theorem fderiv_comp :
fderiv 𝕜 (fun x => (f (g x)))
=
fun x => fun dx =>L[K] fderiv K f (g x) (fderiv K g x dx) := ...
@[fun_trans]
theorem fderiv_id :
(fderiv K fun x : X => x) = fun _ => fun dx =>L[K] dx := ...
noncomputable
def sqrt (y : R) : R := (fun x => x^2)⁻¹ y
def mySqrt (y : R) : Approx P (sqrt y) := ...
#check mySqrt.is_approx -- "∀ y, sqrt y = limit p, mySqrt p y"
#check P -- Filter ApproxParam
#eval mySqrt {absTol := 1e-9} 2.0 -- 1.414214
#eval mySqrt {maxSteps := 1} 2.0 -- 1.5
def saxpy (a : Float) (x y : Float^[n]) := a•x+y
def saxpy_optimized (a : Float) (x y : Float^[n]) := x.mapIdx (fun i xi => a*xi + y[i])
?
def_optimize saxpy by
simp only [HAdd.hAdd,Add.add,HSMul.hSMul,SMul.smul]
simp only [mapMono_mapIdxMono]
structure Rand (X : Type) [MeasurableSpace X] where
μ : Erased (Measure X)
is_prob : IsProbabilityMeasure μ.out
rand : RandG StdGen X
def test (θ : R) : Rand R := do
let b ← flip θ
if b then
pure 0
else
pure (-θ/2)
completeness
compactness
better behavior of function spaces e.g. cartesian closed category