Skip to content

Commit

Permalink
reorganize diffeology
Browse files Browse the repository at this point in the history
  • Loading branch information
lecopivo committed Nov 1, 2024
1 parent cba9f72 commit 9f428f1
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 35 deletions.
145 changes: 145 additions & 0 deletions SciLean/Analysis/Diffeology/Array.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import SciLean.Analysis.Diffeology.Basic
import SciLean.Analysis.Diffeology.NormedSpace
import SciLean.Data.ArrayN

namespace SciLean


namespace Diffeology.Array.Util
def StableSize (f : α → Array β) (n : ℕ) := ∀ a, n = (f a).size

def fixSize (f : α → Array β) (n) (hn : StableSize f n) : α → ArrayN β n :=
fun a => ArrayN.mk (f a) (by simp[hn a])

@[simp]
theorem fixSize_comp [Inhabited α] (g : α → β) (f : β → Array γ) (n) (hn : StableSize f n) :
fixSize f n hn ∘ g = fixSize (f ∘ g) n (by intro a; simp[hn (g a)]) := by
unfold fixSize; funext a; simp

@[simp]
theorem fixSize_arrayN_data (f : α → ArrayN β n) :
fixSize (fun x => (f x).1) n (by intro x; simp[(f x).2.symm]) = f := by
unfold fixSize
simp

theorem differentiable_fixSize
{X} [NormedAddCommGroup X] [NormedSpace ℝ X]
{Y} [NormedAddCommGroup Y] [NormedSpace ℝ Y]
(f : X → Array Y) (n m) (hn : StableSize f n) (hm : StableSize f m)
(hf : Differentiable ℝ (fixSize f n hn)) : Differentiable ℝ (fixSize f m hm) := by
have h : m = n := by simp[hn 0, (hm 0).symm]
subst h
apply hf


theorem fderiv_fixSize_cast
{X} [NormedAddCommGroup X] [NormedSpace ℝ X]
{Y} [NormedAddCommGroup Y] [NormedSpace ℝ Y]
(f : X → Array Y) (x dx) (n) (hn : StableSize f n) (m) (h : m = n) :
fderiv ℝ (fixSize f n hn) x dx = cast (by simp_all) (fderiv ℝ (fixSize f m (by simp_all)) x dx) := by
subst h
simp

end Diffeology.Array.Util
open Diffeology.Array.Util

variable
{X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X]

instance : Diffeology (Array X) where
plots n f := ∃ (h : StableSize f (f 0).size),
Differentiable ℝ (fun x => fixSize f (f 0).size h x)
smooth_comp := by
intros n m p f hp hf; simp_all[Membership.mem,Set.Mem];
cases' hp with n' hp
-- cases' hp with hn hp
constructor
have h := (Differentiable.comp hp hf)
simp at h
apply differentiable_fixSize _ _ _ _ _ h
intro x; simp[(n' (f x)).symm, n' (f 0)]
const_plot := by
intros n x; simp_all[Membership.mem,Set.Mem,StableSize]
have h : Differentiable ℝ (fun _ : Fin n → ℝ => ArrayN.mk (n:=x.size) x (by simp)) := by fun_prop
convert h


open Classical in
noncomputable
instance : TangentSpace (Array X) (fun x => ArrayN X x.size) where
tangent c _ u du :=
if h : StableSize c (c 0).size then
cast (by rw[h u]) (fderiv ℝ (fun x => fixSize c _ h x) u du)
else
0

smooth_comp := by
intros n m p f hp hf u du
have a := Classical.choose hp
have b := Classical.choose (Diffeology.smooth_comp hp hf)
simp_all
conv =>
lhs
enter [2,1]
conv =>
enter [2]
equals ((fixSize p _ (by intro x; simp[(a x).symm, a (f 0)])) ∘ f) => funext x; unfold fixSize; simp
rw[fderiv.comp (hf:=by fun_prop)
(hg:=by apply differentiable_fixSize (hf := Classical.choose_spec hp))]
simp[Function.comp_def]

let n := (p (f 0)).size; let m := (p 0).size
rw [fderiv_fixSize_cast (n:=n) (m:=m)]
simp; simp[a (f 0),m]

tangent_const := by
intros x dx t dt
simp; dsimp; intro h
have h : (fderiv ℝ (fun _ => ArrayN.mk (n:=dx.size) dx rfl) t) dt = 0 := by fun_trans
exact h

curve x dx t := (ArrayN.mk x rfl + t 0 • dx).1
curve_at_zero := by simp
curve_is_plot := by
intro x dx
simp[Diffeology.plots,Membership.mem,Set.Mem]
apply Exists.intro (by intro x; simp)
apply differentiable_fixSize (n:=x.size) (hn:=by intro x; simp)
simp; fun_prop
tangent_curve_at_zero := by
intros x dx dt; simp;
have : StableSize (fun t : Fin 1 → ℝ => (ArrayN.mk x (by rfl) + t 0 • dx).data) x.size := by intro x; simp
simp_all
let m := x.size
rw [fderiv_fixSize_cast (n:=_) (m:=m)]
simp; fun_trans; simp
tangent_linear := by
intro n f ⟨hf,hf'⟩ t
constructor <;> (simp[hf]; simp[hf t])




-- def arrayPlot {n} {p : (Fin n → ℝ) → Array X} (hp : p ∈ Diffeology.plots

variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X]

theorem Array.get.arg_a.MDifferentiable_rule (i : ℕ) (x₀ : X) :
MDifferentiable (fun x : Array X => x.getD i x₀) where
plot_preserving := by
intro n p hp
simp[Function.comp_def]
let m : ℕ := (p 0).size
let p' := fixSize p (p 0).size hp.1
if hi : i < m then
let i' : Fin m := ⟨i, hi⟩
have h : (fun x => (p x)[i]?.getD x₀) = (fun x => (p' x)[i']) := sorry
rw[h]
have : Differentiable ℝ (fun x => p' x) := fun x => hp.2 x
intro x; fun_prop
else
have h : (fun x => (p x)[i]?.getD x₀) = (fun x => x₀) := by sorry
rw[h]
intro x; fun_prop

plot_independence := sorry
85 changes: 50 additions & 35 deletions SciLean/Analysis/Diffeology/Basic.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import SciLean.Tactic.Autodiff
import SciLean.Data.ArrayN

import SciLean.Analysis.Diffeology.Util

namespace SciLean

open Diffeology.Util

/-- Diffeology on `X` says that which curves are differentiable. -/
class Diffeology (X : Type v) where
plots (n : ℕ) : Set ((Fin n → ℝ) → X)
Expand All @@ -10,7 +15,6 @@ class Diffeology (X : Type v) where
const_plot (n : ℕ) (x : X) : (fun _ => x) ∈ plots n



open Diffeology in
class TangentSpace (X : Type v) [Diffeology X] (TX : outParam (X → Type w)) [∀ x, outParam <| AddCommGroup (TX x)] [∀ x, outParam <| Module ℝ (TX x)] where
/-- Map assigning tangent vectors to plots. -/
Expand All @@ -20,7 +24,7 @@ class TangentSpace (X : Type v) [Diffeology X] (TX : outParam (X → Type w)) [
(hp : p ∈ plots m) (hf : Differentiable ℝ f) (x dx) :
tangent (p∘f) (smooth_comp hp hf) x dx = tangent p hp (f x) (fderiv ℝ f x dx)
/-- Tangent of constant function is zero. -/
tangent_const {x : X} {t dt} : tangent (fun _ : Fin n → ℝ => x) (const_plot n x) t dt = 0
tangent_const {n} (x : X) (t dt) : tangent (fun _ : Fin n → ℝ => x) (const_plot n x) t dt = 0

/-- Canonical curve going through `x` in direction `dx`. -/
curve (x : X) (dx : TX x) : (Fin 1 → ℝ) → X
Expand All @@ -40,9 +44,9 @@ attribute [simp] TangentSpace.curve_at_zero TangentSpace.tangent_curve_at_zero T


variable
{X : Type*} {TX : X → Type*} [Diffeology X] [∀ x, AddCommGroup (TX x)] [∀ x, Module ℝ (TX x)] [TangentSpace X TX]
{Y : Type*} {TY : Y → Type*} [Diffeology Y] [∀ y, AddCommGroup (TY y)] [∀ y, Module ℝ (TY y)] [TangentSpace Y TY]
{Z : Type*} {TZ : Z → Type*} [Diffeology Z] [∀ z, AddCommGroup (TZ z)] [∀ z, Module ℝ (TZ z)] [TangentSpace Z TZ]
{X : Type*} {TX : outParam (X → Type*)} [Diffeology X] [∀ x, AddCommGroup (TX x)] [∀ x, Module ℝ (TX x)] [TangentSpace X TX]
{Y : Type*} {TY : outParam (Y → Type*)} [Diffeology Y] [∀ y, AddCommGroup (TY y)] [∀ y, Module ℝ (TY y)] [TangentSpace Y TY]
{Z : Type*} {TZ : outParam (Z → Type*)} [Diffeology Z] [∀ z, AddCommGroup (TZ z)] [∀ z, Module ℝ (TZ z)] [TangentSpace Z TZ]



Expand Down Expand Up @@ -96,27 +100,21 @@ theorem MDifferentiable.comp_rule (f : Y → Z) (g : X → Y)
exact hf.plot_independence hp' hq' (by simp_all) (hg.plot_independence hp hq hx hdx)


@[fun_trans]
theorem mderiv.id_rule :
mderiv (fun x : X => x) = fun _ dx => dx := by

have h : MDifferentiable (fun x : X => x) := by fun_prop
unfold mderiv; simp[h, Function.comp_def]

@[fun_trans]
theorem mderiv.const_rule :
mderiv (fun _ : X => y) = fun _ _ => (0 : TY y) := by

have h : MDifferentiable (fun _ : X => y) := by fun_prop
unfold mderiv; simp[h, Function.comp_def]


@[simp]
theorem cast_apply (f : α → β) (a : α) (h' : (α → β) = (α → β')) (h : β = β' := by simp_all) :
(cast h' f) a = cast h (f a) := by subst h; simp

@[simp]
theorem cast_smul_cast {α} {X : α → Type u} [∀ a, SMul R (X a)] (a a') (r : R) (x : X a) (h : a = a' := by simp_all) :
cast (show X a' = X a by simp_all) (r • cast (by simp_all) x) = r • x := by subst h; simp

@[fun_trans]
theorem mderiv.comp_rule (f : Y → Z) (g : X → Y)
(hf : MDifferentiable f) (hg : MDifferentiable g) :
Expand Down Expand Up @@ -156,42 +154,59 @@ theorem mderiv.comp_rule (f : Y → Z) (g : X → Y)
simp_all [mderiv,hf,hg,q,y,dy]





def FinAdd.fst (x : Fin (n + m) → ℝ) : Fin n → ℝ := fun i => x ⟨i.1, by omega⟩
def FinAdd.snd (x : Fin (n + m) → ℝ) : Fin m → ℝ := fun i => x ⟨i.1 + n, by omega⟩
def FinAdd.mk (x : Fin n → ℝ) (y : Fin m → ℝ) : Fin (n + m) → ℝ :=
fun i => if h : i < n then x ⟨i.1, by omega⟩ else y ⟨i.1 - n, by omega⟩

@[simp]
theorem FinAdd.fst_mk (x : Fin n → ℝ) (y : Fin m → ℝ) : fst (mk x y) = x := by
simp (config:={unfoldPartialApp:=true}) [fst,mk]
@[simp]
theorem FinAdd.snd_mk (x : Fin n → ℝ) (y : Fin m → ℝ) : snd (mk x y) = y := by
simp (config:={unfoldPartialApp:=true}) [snd,mk]

variable (X Y)
structure DiffeologyMap where
val : X → Y
property : MDifferentiable val
variable {X Y}

open Diffeology in
instance : Diffeology (X → Y) where
instance : Diffeology (DiffeologyMap X Y) where
plots := fun n p => ∀ m, ∀ q ∈ plots m (X:=X),
(fun x : Fin (n + m) → ℝ => p (FinAdd.fst x) (q (FinAdd.snd x))) ∈ plots (n+m)
(fun x : Fin (n + m) → ℝ => (p (FinAdd.fst x)).1 (q (FinAdd.snd x))) ∈ plots (n+m)
smooth_comp := by
intros n m p f hp hf
intros m' q hq
let f' : (Fin (n + m') → ℝ) → (Fin (m + m') → ℝ) :=
fun x => FinAdd.mk (f (FinAdd.fst x)) (FinAdd.snd x)
have hf' : Differentiable ℝ f' := by sorry
have hf' : Differentiable ℝ f' := by
simp (config:={unfoldPartialApp:=true}) [f']; fun_prop
have hp' := Diffeology.smooth_comp (hp m' q hq) hf'
simp [Function.comp_def,f'] at hp'
exact hp'
const_plot := by sorry_proof
const_plot := by
intros n f m p hp
exact smooth_comp (n:=n+m) (f:=FinAdd.snd) (f.2.plot_preserving _ hp) (by unfold FinAdd.snd; fun_prop)




variable [Diffeology ℝ] [TangentSpace ℝ (fun _ => ℝ)]
structure TangentBundle (TX : (x : X) → Type*) [∀ x, Diffeology (TX x)]
[∀ x, AddCommGroup (TX x)] [∀ x, Module ℝ (TX x)] [∀ x, TangentSpace (TX x) (fun _ => (TX x))]
where
lift : (c : DiffeologyMap ℝ X) → (s : ℝ) → (v : TX (c.1 s)) → (t : ℝ) → TX (c.1 t)

lift_inv (c : DiffeologyMap ℝ X) (s : ℝ) (v : TX (c.1 s)) (t : ℝ) :
lift c t (lift c s v t) s = v

lift_trans (c : DiffeologyMap ℝ X) (s : ℝ) (v : TX (c.1 s)) (t t' : ℝ) :
lift c t (lift c s v t) t' = lift c s v t'

lift_shift (c : DiffeologyMap ℝ X) (s : ℝ) (v : TX (c.1 s)) (t h : ℝ) :
lift c s v t = cast (by simp) (lift ⟨fun t => c.1 (t+h), sorry⟩ (s-h) (cast (by simp) v) (t-h))


structure TDiffeologicalMap (f : (x : X) → TX x) where

#exit

instance
{X : Type*} {TX : X → Type*} [Diffeology X]
{Y : Type*} {TY : Y → Type*} [Diffeology Y] [∀ y, AddCommGroup (TY y)] [∀ y, Module ℝ (TY y)] [TangentSpace Y TY] :
TangentSpace (X → Y) (fun f => (x : X) → (TY (f x))) where
{Y : Type*} {TY : Y → Type*} [Diffeology Y]
[∀ x, AddCommGroup (TX x)] [∀ x, Module ℝ (TX x)] [TangentSpace X TX]
[∀ y, AddCommGroup (TY y)] [∀ y, Module ℝ (TY y)] [TangentSpace Y TY] :
TangentSpace (DiffeologyMap X Y) (fun f => (x : X) → (TY (f.1 x))) where
-- {n : ℕ} (c : (Fin n → ℝ) → X) (hc : c ∈ plots n (X:=X)) (x dx : (Fin n) → ℝ) : TX (c x)
tangent {n} c hc u du x :=
let q := fun _ : Fin 0 => x
Expand All @@ -206,4 +221,4 @@ instance

curve f df t := fun x => TangentSpace.curve (f x) (df x) t
curve_at_zero := by intros; simp
curve_is_plot := by simp_all[Diffeology.plots]; intros f df n q hq; simp
curve_is_plot := by simp_all[Diffeology.plots]; intros f df x; simp
61 changes: 61 additions & 0 deletions SciLean/Analysis/Diffeology/NormedSpace.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import SciLean.Analysis.Diffeology.Basic

namespace SciLean

variable
{X:Type*} [NormedAddCommGroup X] [NormedSpace ℝ X]
{Y:Type*} [NormedAddCommGroup Y] [NormedSpace ℝ Y]

instance : Diffeology X where
plots n f := Differentiable ℝ f
smooth_comp := by
intros; simp_all[Membership.mem,Set.Mem]; fun_prop
const_plot := by
intros; simp_all[Membership.mem,Set.Mem]

noncomputable
instance : TangentSpace X (fun _ => X) where
tangent c _ t dt := fderiv ℝ c t dt
smooth_comp := by
intros n m p f hp hf t dt
simp[Diffeology.plots,Membership.mem,Set.Mem] at hp
simp_all[Membership.mem,Set.Mem,Function.comp_def]; fun_trans
tangent_const := by intros; simp_all
curve x dx t := x + t 0 • dx
curve_at_zero := by simp
curve_is_plot := by intros; simp_all[Membership.mem,Set.Mem,Diffeology.plots]; fun_prop
tangent_curve_at_zero := by intros; fun_trans
tangent_linear := by intros; constructor <;> simp


set_option trace.Meta.Tactic.fun_trans true in
@[fun_prop]
theorem mdifferentiable_differentiable (f : X → Y) (hf : Differentiable ℝ f) : MDifferentiable f where
plot_preserving p hp x := by
simp[Function.comp_def]; have := hp x
fun_prop

plot_independence {n p q} x hp hq hx hdx := by
have := hp x; have := hq x
simp_all [TangentSpace.tangent,Function.comp_def]
fun_trans; simp_all


@[simp, simp_core]
theorem mderiv_fderiv (f : X → Y) (hf : Differentiable ℝ f := by fun_prop) :
mderiv f = fun x dx => fderiv ℝ f x dx := by
funext x dx
have : MDifferentiable f := by fun_prop;
have := hf x
unfold mderiv; simp_all[TangentSpace.tangent,TangentSpace.curve,Function.comp_def]
fun_trans



variable
{E : Type*} {TE : outParam (E → Type*)} [Diffeology E] [∀ e, AddCommGroup (TE e)] [∀ e, Module ℝ (TE e)] [TangentSpace E TE]

theorem aa (f : Y → E) (g : X → Y) (hf : MDifferentiable f) (hg : Differentiable ℝ g) :
MDifferentiable (fun x => f (g x)) := by fun_prop

#print axioms aa
Loading

0 comments on commit 9f428f1

Please sign in to comment.