import Mathlib.Algebra.BigOperators.Group.List.Basic import Mathlib.Algebra.Group.Prod import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Analysis.LocallyConvex.WithSeminorms import Mathlib.Probability.Distributions.Exponential import Mathlib.Probability.Independence.Basic namespace OAI namespace PlanarFPP open Set MeasureTheory ProbabilityTheory Filter open scoped Topology abbrev Vertex := ℤ × ℤ abbrev Edge := Vertex × Bool inductive Step where | east | west | north | south deriving DecidableEq def Step.delta : Step → Vertex | .east => (1, 0) | .west => (-1, 0) | .north => (0, 1) | .south => (0, -1) def Step.edge (p : Vertex) : Step → Edge | .east => (p, false) | .west => (p + (-1, 0), false) | .north => (p, true) | .south => (p + (0, -1), true) def displacement (ds : List Step) : Vertex := (ds.map Step.delta).sum def pathCost (τ : Edge → ℝ) (p : Vertex) : List Step → ℝ | [] => 0 | d :: ds => τ (d.edge p) + pathCost τ (p + d.delta) ds abbrev Plane := EuclideanSpace ℝ (Fin 2) noncomputable def latticeFloor (v : Plane) : Vertex := (⌊v 0⌋, ⌊v 1⌋) noncomputable def passageTime (τ : Edge → ℝ) (p q : Vertex) : ℝ := sInf {t | ∃ ds : List Step, p + displacement ds = q ∧ pathCost τ p ds = t} structure TimeConstantNorm (μ : Plane → ℝ) : Prop where nonneg : ∀ v, 0 ≤ μ v zero_iff : ∀ v, μ v = 0 ↔ v = 0 triangle : ∀ v w, μ (v + w) ≤ μ v + μ w homogeneous : ∀ (a : ℝ) v, μ (a • v) = |a| * μ v structure ExponentialEnvironment {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) (τ : Edge → Ω → ℝ) : Prop where probability : IsProbabilityMeasure P measurable : ∀ e, Measurable (τ e) independent : iIndepFun τ P marginal : ∀ e, Measure.map (τ e) P = expMeasure 1 def IsTimeConstant {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) (τ : Edge → Ω → ℝ) (μ : Plane → ℝ) : Prop := ∀ v : Plane, ∀ᵐ ω ∂P, Tendsto (fun t : ℝ => passageTime (fun e => τ e ω) (0, 0) (latticeFloor (t • v)) / t) atTop (𝓝 (μ v)) def DifferentiableAwayFromOrigin (μ : Plane → ℝ) : Prop := ∀ v : Plane, v ≠ 0 → ∃ ℓ : Plane →L[ℝ] ℝ, HasFDerivAt μ ℓ v def UniqueNormalizedSupports (μ : Plane → ℝ) : Prop := ∀ v : Plane, μ v = 1 → ∃! ℓ : Plane →L[ℝ] ℝ, ℓ v = 1 ∧ ∀ w, ℓ w ≤ μ w def C1UnitSphere (μ : Plane → ℝ) : Prop := ∀ v : Plane, μ v = 1 → ∃ U : Set Plane, IsOpen U ∧ v ∈ U ∧ ∃ g : Plane → ℝ, ContDiffOn ℝ 1 g U ∧ (∀ w ∈ U, μ w = 1 ↔ g w = 0) ∧ ∀ w ∈ U, g w = 0 → ∃ ℓ : Plane →L[ℝ] ℝ, HasFDerivAt g ℓ w ∧ ℓ ≠ 0 def HasC1CurveChart (S : Set Plane) (v : Plane) : Prop := ∃ U : Set Plane, IsOpen U ∧ v ∈ U ∧ v ∈ S ∧ ∃ γ : ℝ → Plane, ∃ θ : Plane → ℝ, ContDiff ℝ 1 γ ∧ ContinuousOn θ U ∧ (∀ t, γ t ∈ S ∩ U) ∧ (∀ t, θ (γ t)=t) ∧ (∀ z ∈ S ∩ U, γ (θ z)=z) ∧ (∀ t, ∃ d : Plane, HasDerivAt γ d t ∧ d ≠ 0) theorem manuscriptMain (Ω : Type) [MeasurableSpace Ω] (P : Measure Ω) (τ : Edge → Ω → ℝ) (henv : ExponentialEnvironment P τ) : ∃ μ : Plane → ℝ, TimeConstantNorm μ ∧ IsTimeConstant P τ μ ∧ DifferentiableAwayFromOrigin μ ∧ UniqueNormalizedSupports μ ∧ C1UnitSphere μ ∧ (∀ v ∈ frontier {z | μ z ≤ 1}, ∃! L : Set Plane, ∃ g : Plane →L[ℝ] ℝ, g ≠ 0 ∧ (∀ z, μ z ≤ 1 → g z ≤ g v) ∧ L={z | g z=g v}) ∧ (∀ v ∈ frontier {z | μ z ≤ 1}, HasC1CurveChart (frontier {z | μ z ≤ 1}) v) := by sorry end PlanarFPP end OAI