openAI-math-dataset / lean /ComparatorChallenges /BalancedThreeStack.lean
roseking's picture
Add lean source and binary files
dae740b verified
Raw History Blame
8.69 kB
7
inductive Direction where
body · 2 lines
  | stay | left | right
  deriving DecidableEq
11
instance : Fintype Direction :=
body · 1 line
  ⟨{.stay, .left, .right}, by intro d; cases d <;> simp⟩
14
structure Transition (Q Γ : Type*) where
body · 3 lines
  state : Q
  write : Γ
  move : Direction
20
structure FiniteMachine where
body · 6 lines
  states : ℕ
  symbols : ℕ
  initial : Fin (states + 1)
  blank : Fin (symbols + 1)
  transition : Fin (states + 1) → Fin (symbols + 1) →
    Option (Recorder.Transition (Fin (states + 1)) (Fin (symbols + 1)))
28
abbrev Input (M : FiniteMachine) := List (Fin (M.symbols + 1))
30
structure TapeConfiguration (M : FiniteMachine) where
body · 3 lines
  state : Fin (M.states + 1)
  head : ℤ
  tape : ℤ → Fin (M.symbols + 1)
35
def initialConfiguration (M : FiniteMachine) (w : Input M) : TapeConfiguration M :=
body · 1 line
  ⟨M.initial, 0, fun z => if 0 ≤ z then w[z.toNat]?.getD M.blank else M.blank⟩
38
def machineStep (M : FiniteMachine) (c : TapeConfiguration M) : Option (TapeConfiguration M) :=
body · 3 lines
  (M.transition c.state (c.tape c.head)).map fun v =>
    ⟨v.state, c.head + (match v.move with | .stay => 0 | .left => -1 | .right => 1),
      Function.update c.tape c.head v.write⟩
43
def Halts (M : FiniteMachine) (w : Input M) : Prop :=
body · 2 lines
  ∃ c, Relation.ReflTransGen (fun c d => machineStep M c = some d)
    (initialConfiguration M w) c ∧ machineStep M c = none
47
def Recorder.Direction.number : Recorder.Direction → ℕ
body · 3 lines
  | .stay => 0
  | .left => 1
  | .right => 2
52
def FiniteMachine.code (M : FiniteMachine) : ℕ :=
body · 4 lines
  Encodable.encode (M.states, M.symbols, M.initial.val, M.blank.val,
    (List.finRange (M.states + 1)).map fun q =>
      (List.finRange (M.symbols + 1)).map fun a =>
        (M.transition q a).map fun v => (v.state.val, v.write.val, v.move.number))
58
def inputCode (M : FiniteMachine) (w : Input M) : ℕ :=
body · 1 line
  Encodable.encode (M.code, w.map Fin.val)
61
abbrev Space := Fin 3 → ℝ
62
abbrev Field (F : Type*) := ℝ → Space → F
63
abbrev Velocity := Field Space
64
abbrev Pressure := Field ℝ
65
abbrev Family (F : Type*) := (M : FiniteMachine) → Input M → F
66
abbrev MaterialFlow := ℝ → Space → Space
67
abbrev MultiIndex := List (Option (Fin 3))
68
abbrev RationalPoint := ℚ × (Fin 3 → ℚ)
77
def timeD (v : Field F) : Field F :=
body · 1 line
  fun t x => derivWithin (fun s => v s x) (Set.Ici 0) t
80
def spaceD (i : Fin 3) (v : Field F) : Field F :=
body · 1 line
  fun t x => fderiv ℝ (v t) x (Pi.single i 1)
83
def mixedD : MultiIndex → Field F → Field F
body · 3 lines
  | [], v => v
  | none :: a, v => timeD (mixedD a v)
  | some i :: a, v => spaceD i (mixedD a v)
88
def spatialD : List (Fin 3) → Field F → Field F
body · 2 lines
  | [], v => v
  | i :: a, v => spaceD i (spatialD a v)
92
def Smooth (v : Field F) : Prop :=
body · 1 line
  ContDiffOn ℝ (⊤ : ℕ∞) (fun z : ℝ × Space => v z.1 z.2) (Set.Ici 0 ×ˢ Set.univ)
95
def BoundedMixed (v : Field F) : Prop :=
body · 1 line
  ∀ a : MultiIndex, ∃ C : ℝ, 0 ≤ C ∧ ∀ t, 0 ≤ t → ∀ x, ‖mixedD a v t x‖ ≤ C
98
def CH (k : ℕ) (v : Field F) : Prop :=
body · 4 lines
  ∀ a : List (Fin 3), a.length ≤ k →
    ∃ V : ℝ → Lp F 2 (volume : Measure Space),
      ContinuousOn V (Set.Ici 0) ∧
      ∀ t, 0 ≤ t → (V t : Space → F) =ᵐ[volume] spatialD a v t
104
def C1L2 (v : Field F) : Prop :=
body · 6 lines
  ∃ V W : ℝ → Lp F 2 (volume : Measure Space),
    ContinuousOn V (Set.Ici 0) ∧ ContinuousOn W (Set.Ici 0) ∧
    ∀ t, 0 ≤ t →
      (V t : Space → F) =ᵐ[volume] v t ∧
      (W t : Space → F) =ᵐ[volume] timeD v t ∧
      HasDerivWithinAt V (W t) (Set.Ici 0) t
112
def div (u : Velocity) (t : ℝ) (x : Space) : ℝ :=
body · 1 line
  ∑ i, spaceD i u t x i
115
def laplacian (u : Velocity) : Velocity :=
body · 1 line
  fun t x => ∑ i, spaceD i (spaceD i u) t x
118
def convection (u : Velocity) : Velocity :=
body · 1 line
  fun t x => ∑ i, (u t x i) • spaceD i u t x
121
def gradient (p : Pressure) (t : ℝ) (x : Space) : Space :=
body · 1 line
  fun i => spaceD i p t x
124
def affineForce (f₀ f₁ : Velocity) (ν : ℝ) : Velocity :=
body · 1 line
  fun t x => f₀ t x + ν • f₁ t x
127
def inertialCoefficient (u : Velocity) : Velocity :=
body · 1 line
  fun t x => timeD u t x + convection u t x
130
def viscousCoefficient (u : Velocity) : Velocity :=
body · 1 line
  fun t x => -laplacian u t x
133
def ZeroDataSolution (ν : ℝ) (f u : Velocity) (p : Pressure) : Prop :=
body · 6 lines
  Smooth u ∧ Smooth p ∧
  (∀ x, u 0 x = 0) ∧
  (∀ t, 0 ≤ t → ∀ x, div u t x = 0) ∧
  (∀ t, 0 ≤ t → ∀ x,
    timeD u t x + convection u t x =
      -gradient p t x + ν • laplacian u t x + f t x)
141
def BoundedOnFiniteSlabs (u : Velocity) : Prop :=
body · 3 lines
  ∀ T : ℝ, 0 ≤ T → ∃ C : ℝ, 0 ≤ C ∧
    ∀ t ∈ Set.Icc (0 : ℝ) T, ∀ x,
      ‖u t x‖ ≤ C ∧ ∀ i : Fin 3, ‖spaceD i u t x‖ ≤ C
146
def ComparisonClass (u : Velocity) (p : Pressure) : Prop :=
body · 2 lines
  CH 2 u ∧ C1L2 u ∧ BoundedOnFiniteSlabs u ∧
    ∃ c : ℝ → ℝ, CH 1 (fun t x => p t x - c t)
150
def UniqueInComparison (ν : ℝ) (f U : Velocity) : Prop :=
body · 3 lines
  ∀ u p, ZeroDataSolution ν f u p → ComparisonClass u p →
    (∀ t, 0 ≤ t → ∀ x, u t x = U t x) ∧
    (∀ t, 0 ≤ t → ∀ x y, p t x = p t y)
155
def CommonCompactSupport (U f₀ f₁ : Velocity) : Prop :=
body · 2 lines
  ∃ K : Set Space, IsCompact K ∧
    ∀ t, 0 ≤ t → ∀ x, x ∉ K → U t x = 0 ∧ f₀ t x = 0 ∧ f₁ t x = 0
159
def PeriodicAfterOne (v : Velocity) : Prop :=
body · 1 line
  ∀ t, 1 ≤ t → ∀ x, v (t + 1) x = v t x
162
def IsMaterialFlow (u : Velocity) (X : MaterialFlow) : Prop :=
body · 2 lines
  (∀ a, X 0 a = a) ∧
  ∀ a t, 0 ≤ t → HasDerivWithinAt (fun s => X s a) (u t (X t a)) (Set.Ici 0) t
166
def fixedLabel : Space := ![4, 0, 0]
168
def observer : Set Space :=
body · 1 line
  Set.pi Set.univ (fun _ : Fin 3 => Set.Ioo (-1 : ℝ) 2)
171
def rationalSpace (x : Fin 3 → ℚ) : Space := fun i => (x i : ℝ)
173
def error (n : ℕ) : ℝ := (2 : ℝ)⁻¹ ^ n
175
def EffectiveFamily (v : Family Velocity) : Prop :=
body · 11 lines
  ∃ E : (ℕ × MultiIndex × RationalPoint × ℕ) → (Fin 3 → ℚ),
  ∃ b : (ℕ × MultiIndex) → ℕ,
  ∃ R : ℕ → ℕ,
    Computable E ∧ Computable b ∧ Computable R ∧
    (∀ M w a z n, 0 ≤ z.1 → ∀ i,
      |(E (inputCode M w, a, z, n) i : ℝ) -
        mixedD a (v M w) (z.1 : ℝ) (rationalSpace z.2) i| ≤ error n) ∧
    (∀ M w a t, 0 ≤ t → ∀ x,
      ‖mixedD a (v M w) t x‖ ≤ (b (inputCode M w, a) : ℝ)) ∧
    (∀ M w t, 0 ≤ t → ∀ x,
      (R (inputCode M w) : ℝ) < ‖x‖ → v M w t x = 0)
188
def EffectiveFieldIn (O : Set (ℕ →. ℕ)) (v : Velocity) : Prop :=
body · 7 lines
  ∃ E : (MultiIndex × RationalPoint × ℕ) → (Fin 3 → ℚ),
  ∃ b : MultiIndex → ℕ,
    ComputableIn O E ∧ ComputableIn O b ∧
    (∀ a z n, 0 ≤ z.1 → ∀ i,
      |(E (a, z, n) i : ℝ) -
        mixedD a v (z.1 : ℝ) (rationalSpace z.2) i| ≤ error n) ∧
    (∀ a t, 0 ≤ t → ∀ x, ‖mixedD a v t x‖ ≤ (b a : ℝ))
197
def RealName (name : ℕ → ℚ) (x : ℝ) : Prop :=
body · 1 line
  ∀ n, |(name n : ℝ) - x| ≤ error n
200
def ComputableReal (x : ℝ) : Prop :=
body · 1 line
  ∃ name : ℕ → ℚ, Computable name ∧ RealName name x
203
def nameOracle (name : ℕ → ℚ) : ℕ →. ℕ :=
body · 1 line
  fun n => Part.some (Encodable.encode (name n))
211
theorem balanced_three_stack_realization :
    ∃ U f₀ f₁ : Family Velocity,
    ∃ X : Family MaterialFlow,
    ∃ repeated : FiniteMachine → Velocity,
      EffectiveFamily U ∧ EffectiveFamily f₀ ∧ EffectiveFamily f₁ ∧
      (∀ M, Function.Periodic (repeated M) 1) ∧
      ∀ (M : FiniteMachine) (w : Input M),
        Smooth (U M w) ∧ Smooth (f₀ M w) ∧ Smooth (f₁ M w) ∧
        f₀ M w = inertialCoefficient (U M w) ∧
        f₁ M w = viscousCoefficient (U M w) ∧
        CommonCompactSupport (U M w) (f₀ M w) (f₁ M w) ∧
        BoundedMixed (U M w) ∧
        PeriodicAfterOne (U M w) ∧
        (∀ t, 1 ≤ t → ∀ x, U M w t x = repeated M t x) ∧
        ComparisonClass (U M w) (fun _ _ => 0) ∧
        IsMaterialFlow (U M w) (X M w) ∧
        ((∃ t : ℝ, 0 ≤ t ∧ X M w t fixedLabel ∈ observer) ↔ Halts M w) ∧
        ∀ ν : ℝ, 0 < ν →
          let f := affineForce (f₀ M w) (f₁ M w) ν
proof · 6 lines
          ZeroDataSolution ν f (U M w) (fun _ _ => 0) ∧
          Smooth f ∧ BoundedMixed f ∧ PeriodicAfterOne f ∧
          UniqueInComparison ν f (U M w) ∧
          (ComputableReal ν → EffectiveFieldIn ∅ f) ∧
          (∀ name : ℕ → ℚ, RealName name ν → EffectiveFieldIn {nameOracle name} f) := by
  sorry