statement
stringlengths
1
2.38k
proof
stringlengths
0
5.92k
type
stringclasses
12 values
symbolic_name
stringlengths
1
67
library
stringclasses
91 values
filename
stringclasses
439 values
imports
listlengths
0
13
deps
listlengths
0
7
docstring
stringclasses
553 values
source_url
stringclasses
1 value
commit
stringclasses
1 value
linkArgs
if System.Platform.isWindows then #[] else if System.Platform.isOSX then #["-L/opt/homebrew/opt/openblas/lib", "-L/usr/local/opt/openblas/lib", "-lblas"] else -- assuming linux #["-L/usr/lib/x86_64-linux-gnu/", "-lblas", "-lm"]
def
linkArgs
Root
lakefile.lean
[ "Lake" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
inclArgs
if System.Platform.isWindows then #[] else if System.Platform.isOSX then #["-I/opt/homebrew/opt/openblas/include", "-I/usr/local/opt/openblas/include"] else -- assuming linux #[] package scilean { moreLinkArgs := linkArgs } -- -- require mathlib from git "https:...
def
inclArgs
Root
lakefile.lean
[ "Lake" ]
[ "linkArgs" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
sqrtBabylonian (n : Nat) (x₀ : ℝ) (y : ℝ) : ℝ
match n with | 0 => x₀ | n+1 => sqrtBabylonian n ((x₀ + y/x₀)/2) y
def
sqrtBabylonian
doc.literate
doc/literate/approximations.lean
[ "SciLean", "SciLean.Tactic.ConvIf" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
sqrtBakhshali (n : Nat) (x₀ : ℝ) (y : ℝ) : ℝ
match n with | 0 => x₀ | n+1 => let aₙ := (y - x₀*x₀)/(2*x₀) let bₙ := x₀ + aₙ let x₁ := bₙ - aₙ*aₙ/(2*bₙ) sqrtBakhshali n x₁ y /-! Let's test it out to compute :math:`\sqrt{2} = 1.41421356237\dots` -/ #eval sqrtBabylonian 2 1 2 -- 1.416667 #eval sqrtBakhshali 2 1 2
def
sqrtBakhshali
doc.literate
doc/literate/approximations.lean
[ "SciLean", "SciLean.Tactic.ConvIf" ]
[ "sqrtBabylonian" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
real.sqrt (x : ℝ) : ℝ
sorry
def
real.sqrt
doc.literate
doc/literate/approximations.lean
[ "SciLean", "SciLean.Tactic.ConvIf" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
real.mul_self_sqrt {x : ℝ} (h : 0 ≤ x) : real.sqrt x * real.sqrt x = x
sorry
theorem
real.mul_self_sqrt
doc.literate
doc/literate/approximations.lean
[ "SciLean", "SciLean.Tactic.ConvIf" ]
[ "real.sqrt" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
real.sqrt_eq_zero_of_nonpos {x : ℝ} (h : ¬(0 ≤ x)) : real.sqrt x = 0
sorry
theorem
real.sqrt_eq_zero_of_nonpos
doc.literate
doc/literate/approximations.lean
[ "SciLean", "SciLean.Tactic.ConvIf" ]
[ "real.sqrt" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
sqrtBabylonian.limit {x : ℝ} (y₀ : ℝ) (hy : y₀ ≥ 0) (hx : 0 ≤ x) : real.sqrt x = limit λ n => sqrtBabylonian n y₀ x
sorry
theorem
sqrtBabylonian.limit
doc.literate
doc/literate/approximations.lean
[ "SciLean", "SciLean.Tactic.ConvIf" ]
[ "real.sqrt", "sqrtBabylonian" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
sqrtBakhshali.limit {x : ℝ} (y₀ : ℝ) (hy : y₀ ≥ 0) (hx : 0 ≤ x) : real.sqrt y = limit λ n => sqrtBakhshali n x₀ y
sorry /-! To build an approximation, we state `approx sqrtApprox := real.sqrt` followed by instructions how to construct such approximation. The type of `sqrtApprox` is `Approx real.sqrt`, which is an object holding couple of useful informations about the approximation: 1. Parameters to control the accuracy of the...
theorem
sqrtBakhshali.limit
doc.literate
doc/literate/approximations.lean
[ "SciLean", "SciLean.Tactic.ConvIf" ]
[ "real.sqrt", "real.sqrt_eq_zero_of_nonpos", "sqrtBabylonian.limit", "sqrtBakhshali" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
square (x : ℝ)
x * x
def
square
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
square_v1 (x : ℝ) : ℝ
x * x argument x isSmooth, diff
def
square_v1
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
square_v2 (x : ℝ) : ℝ
x * x argument x -- specify how to prove smoothness isSmooth := by unfold square_v2; infer_instance, -- specify what the differential is and how to prove it diff := 2 * dx * x by simp[diff, square_v2]; funext x dx; ring
def
square_v2
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
square_v3 (x : ℝ) : ℝ
x * x argument x -- proof is done automatically isSmooth, -- specify how to compute differential diff by simp[square_v3]
def
square_v3
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
square_v4 (x : ℝ) : ℝ
x * x argument x isSmooth, diff_simp by simp[square_v4]
def
square_v4
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
cube (x : ℝ) : ℝ
x * x * x argument x isSmooth := by unfold cube; infer_instance, diff := 3 * dx * x * x by simp[diff,cube]; funext x dx; ring
def
cube
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
cube_v1 (x : ℝ) : ℝ
x * x * x
def
cube_v1
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
cube_v1.arg_x.isSmooth : IsSmooth (λ x => cube_v1 x)
by unfold cube_v1; infer_instance
instance
cube_v1.arg_x.isSmooth
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[ "cube_v1" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
cube_v1.arg_x.diff (x dx : ℝ) : ℝ
3 * dx * x * x
def
cube_v1.arg_x.diff
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
cube_v1.arg_x.diff_simp : ∂ cube_v1 = cube_v1.arg_x.diff
by simp[diff,cube_v1]; funext x dx; ring
theorem
cube_v1.arg_x.diff_simp
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[ "cube_v1", "cube_v1.arg_x.diff", "∂" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
L' (ϕ : X → ℝ) (m : ℝ) (x v : X)
1/2*m*∥v∥² - ϕ x
def
L'
doc.literate
doc/literate/differentiation_in_scilean.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
H (m k : ℝ) (x p : ℝ)
1/(2*m) * ∥p∥² + k/2 * ∥x∥² /-! To compute a derivative of a function `f : ℝ → ℝ` .. math:: \frac{\partial}{\partial x} f(x) \qquad \text{or} \qquad \frac{\partial}{\partial x'}\bigg\rvert_{x'=x} f(x') we write `∇ x, f x` or `λ x => ∇ (x':=x), f x'`. The derivative w.r.t position of the Hamiltonian is -/ #check ...
def
H
doc.literate
doc/literate/harmonic_oscillator.lean
[ "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver" ]
[ "gradient", "solver" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
main : IO Unit
do let substeps := 1 let m := 1.0 let k := 10.0 let evolve := (solver substeps).val m k let x₀ : ℝ := 1.0 let p₀ : ℝ := 0.0 let mut (x,p) := (x₀, p₀) for _ in [0:40] do (x, p) := evolve 0.1 (x, p) -- print for (j : Nat) in [0:20] do if j < 10*(x+1) then IO.print "o" I...
def
main
doc.literate
doc/literate/harmonic_oscillator.lean
[ "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver" ]
[ "solver" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
x : Nat
5 #reduce 5 + x #check differential #check (∂ f) -- ℝ → ℝ → ℝ #check (differential f)
def
x
doc.literate
doc/literate/literate_lean_test.lean
[ "SciLean" ]
[ "∂" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
foo (x : ℝ) (y : ℝ) : ℝ
x*x*y + y argument x isSmooth, diff? argument y isSmooth, diff? #check Nat /- .unfold -/ /-! .. lean4:: unfold -/ #check Bool #eval 1 + 1
def
foo
doc.literate
doc/literate/literate_lean_test.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
invert_first {X₁ X₂ Y₁ Y₂ : Type} [Nonempty X₁] [Nonempty Y₁] [Nonempty X₂] [Nonempty Y₂] (f : X₁×X₂ → Y₁×Y₂) [IsInv f] : f⁻¹ = λ (y₁,y₂) => let g₁
λ x₂ => (λ x₁ => (f (x₁, x₂)).1)⁻¹ y₁ let x₂ := (λ x₂ => (f (g₁ x₂, x₂)).2)⁻¹ y₂ (g₁ x₂, x₂) := sorry
theorem
invert_first
doc.literate
doc/literate/literate_lean_test.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
invert_second {X₁ X₂ Y₁ Y₂ : Type} [Nonempty X₁] [Nonempty Y₁] [Nonempty X₂] [Nonempty Y₂] (f : X₁×X₂ → Y₁×Y₂) [IsInv f] : f⁻¹ = λ (y₁,y₂) => let g₂
λ x₁ => (λ x₂ => (f (x₁, x₂)).2)⁻¹ y₂ let x₁ := (λ x₁ => (f (x₁, g₂ x₁)).1)⁻¹ y₁ (x₁, g₂ x₁) := sorry
theorem
invert_second
doc.literate
doc/literate/literate_lean_test.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
test (p q : Prop) (hp : p) (hq : q): p ∧ q ↔ q ∧ p
by apply Iff.intro . intro h apply And.intro . exact hq -- hoho . exact hp /- hihi -/ . intro h apply And.intro . exact hp . exact hq
theorem
test
doc.literate
doc/literate/literate_lean_test.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
u
⊞[1.0, 2.0]
def
u
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
A
⊞[1.0, 2.0; 3.0, 4.0] -- element access #eval u[1] #eval A[0,1] -- automatic index type inference #check fun i => u[i] #check fun i j => A[i,j] #check fun ij => A[ij] #check fun (i,j) => A[i,j] #eval ∑ i, u[i] #eval ∑ i j, A[i,j] #eval ∏ ij, A[ij] -- lambda notation for arrays #check ⊞ (i : Fin 4) => i.1.toFloat #e...
def
A
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
array1
Id.run do let mut x : Float^[4] := 0 for i in fullRange (Fin 4) do x[i] := i.1.toFloat return x #check array1 #eval array1
def
array1
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
array2
Id.run do let mut x : Float^[4] := 0 for h : i in [0:4] do let i : Fin 4 := ⟨i, by simp_all [Membership.mem]⟩ x[i] := i.1.toFloat return x
def
array2
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
matrix1
Id.run do let mut A : Float^[4,4] := 0 for (i,j) in fullRange (Fin 4 × Fin 4) do A[i,j] := i.1.toFloat + 4 * j.1.toFloat return A #check matrix1 #eval matrix1
def
matrix1
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
dot {n : Nat} (x y : Float^[n]) : Float
∑ i, x[i] * y[i]
def
dot
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
matMul {n m : Nat} (A : Float^[n,m]) (x : Float^[m]) : Float^[n]
⊞ i => ∑ j, A[i,j] * x[j] #eval dot u u #eval matMul A u -- dimension mismatch #check_failure dot u A #check_failure matMul A A -- not general enough in the index type #check_failure dot A A
def
matMul
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[ "dot" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
dot' (x y : Float^[I]) : Float
∑ i, x[i] * y[i] #eval dot' u u #eval dot' A A
def
dot'
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
matMul' (A : Float^[I,J]) (x : Float^[J]) : Float^[I]
⊞ i => ∑ j, A[i,j] * x[j] #eval matMul' A u
def
matMul'
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
T
⊞ (i j k : Fin 2) => i.1.toFloat + 2 * j.1.toFloat + 4 * k.1.toFloat -- test dot on T #eval dot' T T -- test matMul on T -- it works because (T : Float^[Fin 2 × (Fin 2 × Fin 2)]) (A : Float^[Fin 2 × Fin 2]) -- thuse we have (I := Fin 2) (J := Fin 2 × Fin 2) #eval matMul' T A
def
T
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[ "dot'", "matMul'" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
matMul'' (A : Float^[I,J]) (x : Float^[J]) : Float^[I]
Id.run do let mut y : Float^[I] := 0 for i in fullRange I do for j in fullRange J do y[i] += A[i,j] * x[j] return y #eval matMul'' T A
def
matMul''
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
foo (x : ℝ)
x * exp x -- by default `autodiff` can't see through definitions #check (∂ x, foo x) rewrite_by autodiff -- nothing happens unfold foo autodiff -- define new function transformation with `def_fun_trans` def_fun_trans : fderiv ℝ foo by unfold foo; autodiff -- check the new definition and theorem #print foo.arg_...
def
foo
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[ "∂" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
myderiv (f : ℝ → ℝ) (x : ℝ)
fderiv ℝ f x 1
def
myderiv
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
id_rule : myderiv (fun x : ℝ => x) = fun x => 1
by unfold myderiv; fun_trans
theorem
id_rule
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[ "myderiv" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
const_rule (y : ℝ) : myderiv (fun x : ℝ => y) = fun x => 0
by unfold myderiv; fun_trans
theorem
const_rule
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[ "myderiv" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
comp_rule (f g : ℝ → ℝ) (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : myderiv (fun x => f (g x)) = fun x => myderiv f (g x) * myderiv g x
by unfold myderiv; fun_trans[mul_comm]
theorem
comp_rule
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[ "myderiv" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
add_rule (f g : ℝ → ℝ) (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : myderiv (fun x => f x + g x) = fun x => myderiv f x + myderiv g x
by unfold myderiv; fun_trans
theorem
add_rule
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[ "myderiv" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
mul_rule (f g : ℝ → ℝ) (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : myderiv (fun x => f x * g x) = fun x => myderiv f x * g x + f x * myderiv g x
by unfold myderiv; fun_trans[mul_comm,add_comm] -- test `myderiv` with `fun_trans` #check (myderiv (fun x : ℝ => x*x*x*x + x*x)) rewrite_by fun_trans
theorem
mul_rule
doc.talk
doc/talk/august_umbc_lecture.lean
[ "SciLean" ]
[ "myderiv" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
List.toArrayType (l : List α) {n : USize} (h : l.length = n.toNat) [PlainDataType α] : α^[n]
⊞ i => l.get ⟨i.1.toNat,sorry_proof⟩
def
List.toArrayType
examples
examples/Ballistic.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
g
⊞[0.0, -9.81]
def
g
examples
examples/Ballistic.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
ballisticMotion (x v : Float^[2])
(v, g - (5.0 + ‖v‖₂) • v) #generate_revDeriv ballisticMotion x v prop_by unfold ballisticMotion; fprop trans_by unfold ballisticMotion; ftrans noncomputable approx aimToTarget (v₀ : Float^[2]) (optimizationRate : Float) := λ (T : Float) (target : Float^[2]) => let shoot := λ (v : Float^[2]) => ...
def
ballisticMotion
examples
examples/Ballistic.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
shotTrajectoryPoints (n : ℕ) (T : ℝ) (v : ℝ×ℝ) : Array ((ℝ×ℝ)×(ℝ×ℝ))
odeSolve_fixed_dt_array (λ (t : ℝ) (x,v) => ballisticMotion x v) midpoint_step n 0 (0,v) T
def
shotTrajectoryPoints
examples
examples/Ballistic.lean
[ "SciLean" ]
[ "ballisticMotion" ]
Generate `n` trajectory points in the interval [0,T]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
aimStep (target : ℝ×ℝ) (v₀ : ℝ×ℝ)
aimToTarget v₀ (5.0:ℝ) (1:ℝ) target
def
aimStep
examples
examples/Ballistic.lean
[ "SciLean" ]
[]
Do one step of optimization
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
frame : Frame
where xmin := -1 ymin := -1 xSize := 2 width := 400 height := 400
def
frame
examples
examples/BallisticWidget.lean
[ "ProofWidgets.Component.InteractiveSvg", "ProofWidgets.Component.HtmlDisplay", "examples.Ballistic" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
State where v : ℝ×ℝ deriving ToJson, FromJson
structure
State
examples
examples/BallisticWidget.lean
[ "ProofWidgets.Component.InteractiveSvg", "ProofWidgets.Component.HtmlDisplay", "examples.Ballistic" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
isvg : InteractiveSvg State
where init := { v := 0 } frame := frame update time Δt action mouseStart mouseEnd selected getData state := if let .some mouseEnd := mouseEnd then let target : ℝ×ℝ := mouseEnd let newVel := aimStep target state.v { v := newVel } else state render time mouseStart mouseEnd stat...
def
isvg
examples
examples/BallisticWidget.lean
[ "ProofWidgets.Component.InteractiveSvg", "ProofWidgets.Component.HtmlDisplay", "examples.Ballistic" ]
[ "State", "aimStep", "frame", "init", "shotTrajectoryPoints" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
updateSvg (params : UpdateParams State) : RequestM (RequestTask (UpdateResult State))
isvg.serverRpcMethod params
def
updateSvg
examples
examples/BallisticWidget.lean
[ "ProofWidgets.Component.InteractiveSvg", "ProofWidgets.Component.HtmlDisplay", "examples.Ballistic" ]
[ "State" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
SvgWidget : Component (UpdateResult State)
where javascript := include_str ".." / "lake-packages" / "proofwidgets" / "build" / "js" / "interactiveSvg.js"
def
SvgWidget
examples
examples/BallisticWidget.lean
[ "ProofWidgets.Component.InteractiveSvg", "ProofWidgets.Component.HtmlDisplay", "examples.Ballistic" ]
[ "State" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
init : UpdateResult State
{ html := Html.ofTHtml <div>Init!!!</div>, state := { state := isvg.init time := 0 selected := none mousePos := none idToData := isvg.render 0 none none isvg.init |>.idToDataList} } #html <SvgWidget html={init.html} state={init.state}/>
def
init
examples
examples/BallisticWidget.lean
[ "ProofWidgets.Component.InteractiveSvg", "ProofWidgets.Component.HtmlDisplay", "examples.Ballistic" ]
[ "State", "SvgWidget" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
main : IO Unit
do IO.println "fix this test!" #exit let v := DenseVector.ofFn (Array:=FloatArray) (vstrg := .normal) (fun (i : Fin 3) => i.1.toFloat) IO.println s!"v := {v}" IO.println s!"0.1•v := {v.scal 0.1}" IO.println s!"v+v := {v.axpy 1 v}" IO.println s!"‖v‖₂² := {v.nrm2}"
def
main
examples
examples/BlasTest.lean
[ "LeanBLAS" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
A (x : ℝ^{2}) : ℝ^{2}
⊞ i, if i = 0 then x[0] + x[1] else x[0] - x[1] -- We can turn on debugging logging with -- set_option trace.Meta.Tactic.fun_trans.rewrite true in function_properties A (x : ℝ^{2}) argument x IsLin, HasAdjoint, IsSmooth, HasAdjDiff,
def
A
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[]
choose a particular A: (x, y) ↦ (x + y, x - y)
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
λ dx => A dx by unfold A; fun_trans,
abbrev
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
λ x' => ⊞ i, if i = 0 then x'[0] - x'[1] else x'[0] + x'[1] by sorry,
def
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
∂† by unfold adjointDifferential; fun_trans; fun_trans; simp
abbrev
∂†
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
loss (x : ℝ^{2}) : ℝ
⟪x, A x⟫ function_properties loss (x : ℝ^{2}) argument x IsSmooth, HasAdjDiff,
def
loss
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
λ dx => (2 : ℝ) * ⟪dx, A x⟫ by { simp[loss]; fun_trans; -- 'trans' makes me think of 'transitive'. simp; funext dx; -- ⊢ ⟪dx, A x⟫ + ⟪x, A dx⟫ = 2 * ⟪dx, A x⟫ -- ⟪dx, A x⟫ + ⟪x, A dx⟫ -- = ⟪dx, A x⟫ + ⟪A† x, dx⟫ -- by definition of adjoint -- = ⟪dx, A x⟫ + ⟪dx, A† x⟫ -- by symmet...
abbrev
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "loss" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
∂† by { unfold gradient; unfold loss; fun_trans; simp }
abbrev
∂†
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "gradient", "loss" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
gradLoss (x : ℝ^{2}) : ℝ^{2}
∇ loss x
def
gradLoss
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "loss" ]
noncomputable version of gradient of loss
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
gradLoss' (x : ℝ^{2}) : ℝ^{2}
(∇ loss x) rewrite_by { unfold gradient; unfold loss; fun_trans }
def
gradLoss'
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "gradient", "loss" ]
make gradLoss computable by transforming abstract gradient defn into computable definition.
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
TrainIter where iteration : Nat -- iteration count. point : ℝ^{2} -- current point on the circle.. loss_at_point : ℝ -- loss value at current point. gradAmbient : ℝ^{2} -- gradient at current point in ambient space. gradSubmanifold : ℝ^{2}
structure
TrainIter
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[]
Data at each training iteration
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
normalize (p : ℝ^{2}) : ℝ^{2}
p / ‖p‖
def
normalize
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[]
Normalize a vector.
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
project (v : ℝ^{2}) (direction: ℝ^{2}) : ℝ^{2}
⟪v, direction⟫ • direction
def
project
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "direction" ]
Project 'v' along 'direction'.
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
circle_project (x : ℝ^{2})
normalize x
def
circle_project
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "normalize" ]
Project point 'x' to lie on the circle. This is a retraction of (ℝ^2 - origin) onto the embedded S¹.
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
projectToCircleTangentSpace (p : ℝ^{2}) (vec : ℝ^{2}) : ℝ^{2}
vec - project (direction := p) vec
def
projectToCircleTangentSpace
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "direction", "project" ]
project a vector to the tangent space at `p` by deleting the normal component
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
TrainIter.calcAtPoint (i : Nat) (p : ℝ^{2}) : TrainIter
where iteration := i point := p loss_at_point := loss p gradAmbient := gradLoss' p gradSubmanifold := projectToCircleTangentSpace (p := p) (gradLoss' p)
def
TrainIter.calcAtPoint
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "TrainIter", "gradLoss'", "loss", "projectToCircleTangentSpace" ]
Calculate gradient at current point
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
HyperParams where learningRate : ℝ
0.01
structure
HyperParams
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
HyperParams.default : HyperParams
{}
def
HyperParams.default
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "HyperParams" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
TrainIter.nextPoint (hp : HyperParams) (step : TrainIter) : ℝ^{2}
circle_project <| step.point - hp.learningRate • step.gradSubmanifold
def
TrainIter.nextPoint
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "HyperParams", "TrainIter", "circle_project" ]
Step to the next point by gradient descent
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
gradientDescend (init: ℝ^{2}) (nsteps : ℕ) (hp : HyperParams := HyperParams.default) : Array TrainIter
Id.run do let mut cur : ℝ^{2} := circle_project init let mut out := #[] for i in List.range nsteps do let step := TrainIter.calcAtPoint i cur out := out.push <| step cur := step.nextPoint hp return out
def
gradientDescend
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "HyperParams", "HyperParams.default", "TrainIter", "TrainIter.calcAtPoint", "circle_project", "init" ]
run the gradient descent algorithm
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
main : IO Unit
do let init : ℝ^{2} := ⊞ i, if i = 0 then 1 else 0 let losses := gradientDescend init 1000 for loss in losses do IO.println s!"{loss}"
def
main
examples
examples/CircleOptimisation.lean
[ "SciLean" ]
[ "gradientDescend", "init", "loss" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
g : ℝ
9.81
def
g
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
ParticleLagrangian {n} (ϕ : ℝ^{d} → ℝ) (m : ℝ^{n}) (x v : ℝ^{d}^{n}) : ℝ
∑ i, (0.5:ℝ) * m[i] * ∥v[i]∥² - ∑ i, m[i] * ϕ x[i]
def
ParticleLagrangian
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
chainConstraint {n} (l : ℝ^{n}) (x : ℝ^{2}^{n+1}) : Prop
∀ i : Fin n, ∥x[i.succ] - x[⟨i, sorry_proof⟩]∥ = l[i]
def
chainConstraint
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
chainConstraintFun {n} (l : ℝ^{n}) (x : ℝ^{2}^{n+1}) : ℝ^{n}
λ [i] => l[i]*l[i] - ∥x[i.succ] - x[⟨i, sorry_proof⟩]∥²
def
chainConstraintFun
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
chainConstraintLhs {n} (l : ℝ^{n}) (x : ℝ^{2}^{n+1})
λ i : Fin n => ∥x[i.succ] - x[⟨i, sorry_proof⟩]∥
def
chainConstraintLhs
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
chainConstraintRhs {n} (l : ℝ^{n}) (x : ℝ^{2}^{n+1})
λ i : Fin n => l[i]
def
chainConstraintRhs
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
endPoints {n n' : Nat} (l r : ℝ^{2}) (x : ℝ^{2}^{n+1}) (x' : ℝ^{2}^{n'+1}) : ℝ^{2} × ℝ^{2} × ℝ^{2} × ℝ^{2}
(-- top chain constraints x[0] - l, x[⟨n,sorry⟩] - r, -- bottow chain constraints x'[0] - x[⟨(n+1)/4, sorry⟩], x'[⟨n',sorry⟩] - x[⟨3*(n+1)/4, sorry⟩]) argument x isSmooth, diff, hasAdjDiff, adjDiff argument x' isSmooth, diff, hasAdjDiff, adjDiff #check ode_solve #check ReaderM NewtonSettings X ...
def
endPoints
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "∂", "∂†" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
L' (m : ℝ×ℝ) (x v : ℝ^{2}×ℝ^{2}) : ℝ
(m.1/2) * ∥v.1∥² + (m.2/2) * ∥v.2∥² - m.1 * g * x.1[1] - m.2 * g * x.2[1] argument x isSmooth, diff, hasAdjDiff, adjDiff argument v isSmooth, diff, hasAdjDiff, adjDiff
def
L'
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
parm (l : ℝ × ℝ) (θ : ℝ^{2}) : ℝ^{2}×ℝ^{2}
let d₁ : ℝ^{2} := ⟨Math.sin θ[0], Math.cos θ[0]⟩ let d₂ : ℝ^{2} := ⟨Math.sin θ[1], Math.cos θ[1]⟩ -- (l.1 * d₁, l.1 * d₁ + l.2 * d₂) (d₁, d₂) argument θ isSmooth
def
parm
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
parm' {n} (l : ℝ^{n}) (θ : ℝ^{n}) (x₀ : ℝ^{2}) : (ℝ^{2})^{n+1}
Id.run do let mut x : (ℝ^{2})^{n+1} := 0 let mut y := x₀ for h : i in [0:n] do let i : Fin n := ⟨i, h.2⟩ let next := i.succ let dir : ℝ^{2} := ⟨Math.cos (θ[i]), Math.sin (θ[i])⟩ y += l[i] * dir x[next] := y x
def
parm'
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
parm'' {n} (l : ℝ^{n}) (θ : ℝ^{n}) (x₀ : ℝ^{2}) : (ℝ^{2})^{n+1}
Id.run do let mut x : (ℝ^{2})^{n+1} := 0 let mut y := x₀ for h : i in [0:n] do let i : Fin n := ⟨i, h.2⟩ let next := i.succ let dir : ℝ^{2} := ⟨Math.cos (θ[i]), Math.sin (θ[i])⟩ y := y + l[i] * dir x[next] := y x
def
parm''
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
parm''' {n} (l : ℝ^{n}) (θ : ℝ^{n}) (x₀ : ℝ^{2}) : (ℝ^{2})^{n+1}
funRec (n+1) 0 step (reserveElem (n+1) 0) where step : (n' : Nat) → ((ℝ^{2})^{n'}) → (ℝ^{2})^{n'+1} | 0, x => (λ [i] => x₀) | n'+1, x => let dir : ℝ^{2} := ⟨Math.cos (θ[⟨n',sorry_proof⟩]), Math.sin (θ[⟨n',sorry_proof⟩])⟩ let y := x[⟨n', by simp⟩] + l[⟨n', sorry_proof⟩] * dir pushElem 1 ...
def
parm'''
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
funRec.arg_x.diff_simp {α : Nat → Type} [Vec X] [∀ n, Vec (α n)] (f : (n : Nat) → α n → α (n + 1)) [∀ n, IsSmooth (f n)] (n m : Nat) : ∂ (λ x => funRec n m f x) = λ x dx => (funRec (α:=λ n' => α n' × α n') n m (λ n' (x',dx') => (f n' x', ∂ (f n') x' dx')) (x,dx)).2
sorry_proof
theorem
funRec.arg_x.diff_simp
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "∂" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
funRec.arg_f.diff_simp {α : Nat → Type} [Vec X] [∀ n, Vec (α n)] (f : X → (n : Nat) → α n → α (n + 1)) [∀ n, IsSmooth (λ x => f x n)] [∀ x n, IsSmooth (f x n)] (n : Nat) : ∂ (λ x => funRec n m (f x)) = λ x dx y => (∂ (funRec (α:=λ n' => X × α n') n m (λ n' xy' => (xy'.1, f xy'.1 n' xy'.2))) (x,y) (dx,0))...
sorry_proof
theorem
funRec.arg_f.diff_simp
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "∂" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
parm'''' {n} (l : ℝ^{n}) (θ : ℝ^{n}) (x₀ : ℝ) : ℝ^{n+1}
let step (n' : Nat) (x : ℝ^{n'}) : ℝ^{n'+1} := pushElem (Cont:=(ℝ^{·})) 1 (θ[⟨n',sorry⟩]) x funRec (n+1) 0 step 0 argument θ -- isSmooth := by simp[parm'''']; infer_instance, diff by simp[parm''''] enter [θ,x,a] simp only [funRec.arg_x.diff_simp (α:= λ n' => ℝ^{n} × ℝ^{n'})] simp
def
parm''''
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "funRec.arg_x.diff_simp" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
parm'''' {n} (l : ℝ^{n}) (θ : ℝ^{n}) (x₀ : ℝ^{2}) : (ℝ^{2})^{n+1}
step 1 n (λ [i] => x₀) where step : (n m : Nat) → ((ℝ^{2})^{n+1-m}) → (ℝ^{2})^{n+1} | n, 0, x => x | n, m+1, x => pushElem 1 sorry (step n m x)
def
parm''''
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
L (m l : ℝ×ℝ) (θ ω : ℝ^{2})
(L' m (parm l θ) (ⅆ (t:=0), parm l (θ + (t:ℝ) * ω))) rewrite_by simp
def
L
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "L'", "parm" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
solver (m l : ℝ×ℝ) (steps : Nat) : Impl (ode_solve (LagrangianSystem (L m l)))
by simp [L, pure_impl, PureImpl] conv in (L _ _) => simp [L, L', parm] pattern (differential _); rmlamlet; enter [θ, ω]; simp -- autodiff simp -- Lagrangian is in a nice form now conv => pattern (LagrangianSystem _); whnf admit
def
solver
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "Impl", "L'", "parm" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
solver_0 (m k l : ℝ) (steps : Nat) : Impl (λ x v : Q => (L m k l) x v)
by simp [LagrangianSystem, L, L', parm, gradient] conv => pattern (differential _); rmlamlet; enter [x, dx]; simp -- autodiff simp finish_impl
def
solver_0
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "Impl", "L'", "finish_impl", "gradient", "parm" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
solver_1 (m k l : ℝ) (steps : Nat) : Impl (λ x v : Q => ∇(swap (L m k l) v) x)
by conv in (L _ _ _) => enter [θ, ω] simp [L, L', parm] rmlamlet simp simp [gradient] conv => pattern (differential _); rmlamlet; enter [x, dx]; simp -- autodiff conv in (dual _) => pattern (dual _); rmlamlet; simp -- autodual . finish_impl
def
solver_1
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "Impl", "L'", "finish_impl", "gradient", "parm" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
solver_2 (m k l : ℝ) (steps : Nat) : Impl (λ x v : Q => ∇(∂ (L m k l) x v) v)
by conv in (L _ _ _) => enter [θ, ω] simp [L, L', parm] rmlamlet simp conv => pattern (differential _); enter [x, dx, y]; rmlamlet; simp -- autodiff (we need to introduce all arguments!) conv => -- autograd - part1 pattern (gradient _...
def
solver_2
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "Impl", "L'", "finish_impl", "gradient", "parm", "∂" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
solver_3 (m k l : ℝ) (steps : Nat) : Impl (λ x v : Q => ∂(∇((L m k l) x)) v)
by conv in (L _ _ _) => simp [L, L', parm] { pattern (differential _); rmlamlet; enter [θ, ω]; simp } -- autodiff simp -- Lagrangian is in a nice form now conv => -- autograd - part1 pattern (gradient _) enter [x] simp [gradient] pa...
def
solver_3
examples
examples/DoublePendulum.lean
[ "SciLean.Core", "SciLean.Mechanics", "SciLean.Operators.ODE", "SciLean.Solver.Solver", "SciLean.Data.DataArray", "SciLean.Core.Extra", "SciLean.Functions.Trigonometric", "SciLean.Data.FunRec" ]
[ "Impl", "L'", "finish_impl", "gradient", "parm", "∂" ]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5
ε : ℝ
0.001
def
ε
examples
examples/DoublePendulum2d.lean
[ "SciLean" ]
[]
https://github.com/lecopivo/SciLean
95f8119a2884e9c41f82136523bd5568ea7075c5