Download data/lean/OAI/Probability/CriticalZ3/Relay.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalZ3/Relay.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/CriticalZ3/Relay.lean
-
curl -L -o Relay.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalZ3/Relay.lean
11.4 kB
| import OAI.Probability.CriticalZ3.Scales | |
| namespace OAI | |
| open _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory Classical Filter Topology | |
| open scoped ENNReal BigOperators Matrix | |
| namespace LatticeRelay | |
| open Set | |
| abbrev Vertex := Fin 3 β β€ | |
| def Rect (c w : Vertex) : Set Vertex := {x | β i, |x i - c i| β€ w i} | |
| def Cube (c : Vertex) (s : β€) : Set Vertex := Rect c (fun _ => s) | |
| def Expand (c w : Vertex) (R : β€) : Set Vertex := Rect c (fun i => w i + R) | |
| def DirectedInterval (a s : β€) (positive : Bool) (b : β€) : Prop := | |
| if positive then a β€ b β§ b β€ a+s else a-s β€ b β§ b β€ a | |
| def QuarterFace (u : Vertex) (s : β€) (normal : Fin 3) (signs : Fin 3 β Bool) : Set Vertex := | |
| {x | x normal = u normal + (if signs normal then s else -s) β§ | |
| β i, i β normal β DirectedInterval (u i) s (signs i) (x i)} | |
| def inward (u : Vertex) : Fin 3 β Bool := fun i => decide (u i < 0) | |
| def Prism (r : β€) : Set Vertex := | |
| {x | -10*r β€ x 0 β§ x 0 β€ 30*r+1 β§ | |
| β i : Fin 3, i β 0 β |x i| β€ 10*r} | |
| theorem inward_endpoint_bound {a s W : β€} (_hs : 0 β€ s) (hW : s β€ W) | |
| (ha : |a| β€ W+s) : |a + (if decide (a < 0) then s else -s)| β€ W := by | |
| rw [abs_le] at ha β’ | |
| by_cases h : a < 0 <;> simp [h] <;> omega | |
| theorem inward_interval_bound {a b s W : β€} (hW : s β€ W) (ha : |a| β€ W) | |
| (hb : DirectedInterval a s (decide (a < 0)) b) : |b| β€ W := by | |
| rw [abs_le] at ha β’ | |
| by_cases h : a < 0 <;> simp [DirectedInterval,h] at hb <;> omega | |
| theorem quarterFace_subset_cube {u : Vertex} {s : β€} (hs : 0 β€ s) | |
| (h : Fin 3) (signs : Fin 3 β Bool) : QuarterFace u s h signs β Cube u s := by | |
| intro x hx i | |
| by_cases hi : i = h | |
| Β· subst i | |
| rw [hx.1] | |
| dsimp | |
| cases signs h <;> simp [abs_of_nonneg hs] | |
| Β· have hh := hx.2 i hi | |
| change |x i - u i| β€ s | |
| rw [abs_le] | |
| unfold DirectedInterval at hh | |
| cases hsi : signs i <;> simp [hsi] at hh <;> omega | |
| theorem quarterFace_nonempty {u : Vertex} {s : β€} (hs : 0 β€ s) | |
| (h : Fin 3) (signs : Fin 3 β Bool) : (QuarterFace u s h signs).Nonempty := by | |
| let x : Vertex := fun i => if i = h then u i + (if signs h then s else -s) else u i | |
| refine β¨x,by simp [x],?_β© | |
| intro i hi | |
| dsimp [x] | |
| rw [ite_eq_right hi] | |
| cases signs i <;> simp [DirectedInterval] <;> omega | |
| /-- Generic form of one of the three contraction steps. -/ | |
| theorem contraction_face {r a : β€} (hr : 0 β€ r) (ha : 0 β€ a) (h : Fin 3) | |
| {u : Vertex} | |
| (hu : β i, |u i| β€ if i < h then 2*r+a else 4*r+a) : | |
| QuarterFace u (2*r) h (inward u) β | |
| Rect 0 (fun i => if i β€ h then 2*r+a else 4*r+a) := by | |
| intro x hx i | |
| change |x i - 0| β€ _ | |
| rw [sub_zero] | |
| by_cases hi : i = h | |
| Β· subst i | |
| rw [hx.1] | |
| simp only [le_refl,ite_true,inward] | |
| apply inward_endpoint_bound (by omega) (by omega) | |
| have huu := hu h | |
| simp only [lt_self_iff_false,ite_false] at huu | |
| omega | |
| Β· have hh := hx.2 i hi | |
| dsimp [inward] at hh | |
| apply inward_interval_bound (by dsimp; split_ifs <;> omega) _ hh | |
| have hhi : (i < h) β (i β€ h) := by omega | |
| simpa only [hhi] using hu i | |
| theorem contraction_cube {r a : β€} (_hr : 0 β€ r) (ha : 0 β€ a) | |
| (ha' : 6*r+a < 10*r) (h : Fin 3) {u : Vertex} | |
| (hu : β i, |u i| β€ if i < h then 2*r+a else 4*r+a) : | |
| Cube u (2*r) β Prism r := by | |
| intro x hx | |
| have hu' (i : Fin 3) : |u i| β€ 4*r+a := by | |
| have hu' := hu i | |
| split_ifs at hu' <;> omega | |
| have hxi (i : Fin 3) : |x i| < 10*r := by | |
| have hxu := hx i | |
| change |x i-u i| β€ 2*r at hxu | |
| have huu := hu' i | |
| rw [abs_le] at hxu huu | |
| rw [abs_lt] | |
| omega | |
| have h0 := (abs_lt.mp (hxi 0)) | |
| refine β¨by omega,by omega,?_β© | |
| intro i _ | |
| exact (hxi i).le | |
| def axisCenter (a : β€) : Vertex := fun i => if i = 0 then a else 0 | |
| def forwardInward (u : Vertex) : Fin 3 β Bool := | |
| fun i => if i = 0 then true else decide (u i < 0) | |
| /-- Generic form of each of the ten translation steps, including the final | |
| length 2r+1 step. -/ | |
| theorem translation_face {a s w : β€} (hs : s β€ w) {u : Vertex} | |
| (hu : u β Cube (axisCenter a) w) : | |
| QuarterFace u s 0 (forwardInward u) β Cube (axisCenter (a+s)) w := by | |
| intro x hx i | |
| by_cases hi : i = 0 | |
| Β· subst i | |
| have huu := hu 0 | |
| rw [hx.1] | |
| simpa [forwardInward,axisCenter] using huu | |
| Β· have huu := hu i | |
| have hxx := hx.2 i hi | |
| simp only [forwardInward,hi,ite_false] at hxx | |
| simp only [axisCenter,hi,ite_false,sub_zero] at huu β’ | |
| exact inward_interval_bound hs huu hxx | |
| theorem translation_cube {r R a s w : β€} | |
| (_hR : 0 < R) (hr : 100*(R+1) < r) | |
| (ha0 : 0 β€ a) (ha : a β€ 18*r) (hw : w β€ 2*r+13*R) (hs : s β€ 2*r+1) | |
| {u : Vertex} (hu : u β Cube (axisCenter a) w) : | |
| Cube u s β Prism r := by | |
| intro x hx | |
| have bounds (i : Fin 3) : -(w+s) β€ x i-axisCenter a i β§ | |
| x i-axisCenter a i β€ w+s := by | |
| have hu' := (abs_le.mp (hu i)) | |
| have hx' := (abs_le.mp (hx i)) | |
| dsimp at hu' hx' | |
| omega | |
| have h0 := bounds 0 | |
| simp only [axisCenter,ite_true] at h0 | |
| refine β¨by omega,by omega,?_β© | |
| intro i hi | |
| have h := bounds i | |
| simp only [axisCenter,hi,ite_false,sub_zero] at h | |
| rw [abs_le] | |
| constructor <;> omega | |
| def contractionWidths (r R : β€) (t : β) : Vertex := | |
| fun h => if h.val < t then 2*r+(t : β€)*R else 4*r+(t : β€)*R | |
| def HasInterface (r R : β€) (c w : Vertex) (T : Set Vertex) : Prop := | |
| β u β Expand c w R, β s : β€, s β ({2*r,2*r+1,10*r} : Set β€) β§ | |
| Cube u s β Prism r β§ β h signs, QuarterFace u s h signs β T | |
| theorem contraction_interface {r R : β€} (hR : 0 < R) (hr : 100*(R+1) < r) | |
| {t : β} (ht : t < 3) : | |
| HasInterface r R 0 (contractionWidths r R t) | |
| (Rect 0 (contractionWidths r R (t+1))) := by | |
| intro u hu | |
| let h : Fin 3 := β¨t,htβ© | |
| let a : β€ := (t+1)*R | |
| have ht' : (t : β€) < 3 := by exact_mod_cast ht | |
| have ht0 : (0 : β€) β€ t := by positivity | |
| have ha0 : 0 β€ a := by dsimp [a]; positivity | |
| have ha3 : a β€ 3*R := by dsimp [a]; nlinarith | |
| have huu : β i, |u i| β€ if i < h then 2*r+a else 4*r+a := by | |
| intro i | |
| have hh := hu i | |
| change |u i-0| β€ (if i.val < t then 2*r+(t : β€)*R else 4*r+(t : β€)*R)+R at hh | |
| change |u i| β€ if i.val < t then 2*r+a else 4*r+a | |
| dsimp [a] | |
| rw [add_mul] | |
| by_cases hi : i.val < t <;> simp only [hi,ite_true,ite_false,sub_zero,one_mul] at * <;> omega | |
| refine β¨2*r,by simp,contraction_cube (by omega) ha0 (by omega) h huu,h,inward u,?_β© | |
| intro x hx i | |
| have hb := contraction_face (by omega) ha0 h huu hx i | |
| change |x i-0| β€ if i.val < t+1 then 2*r+(β(t+1) : β€)*R else 4*r+(β(t+1) : β€)*R | |
| have hi : (i β€ h) β i.val < t+1 := by change (i.val β€ t) β _; omega | |
| simpa only [hi,a,Nat.cast_add,Nat.cast_one,Pi.zero_apply] using hb | |
| theorem translation_interface {r R a s w : β€} | |
| (hR : 0 < R) (hr : 100*(R+1) < r) | |
| (ha0 : 0 β€ a) (ha : a β€ 18*r) (hw : w β€ 2*r+13*R) | |
| (hs : s = 2*r β¨ s = 2*r+1) (hsw : s β€ w) : | |
| HasInterface r R (axisCenter a) (fun _ => w-R) (Cube (axisCenter (a+s)) w) := by | |
| intro u hu | |
| have huu : u β Cube (axisCenter a) w := by | |
| intro i | |
| simpa only [Expand,Rect,sub_add_cancel] using hu i | |
| refine β¨s,?_,translation_cube hR hr ha0 ha hw (by rcases hs with rfl|rfl <;> omega) huu, | |
| 0,forwardInward u,translation_face hsw huuβ© | |
| rcases hs with rfl|rfl <;> simp | |
| def routeCenter (r : β€) (i : β) : Vertex := | |
| if i β€ 3 then 0 else axisCenter (if i β€ 12 then 2*r*(i-3 : β) else 20*r+1) | |
| def routeWidths (r R : β€) (i : β) : Vertex := | |
| if i β€ 3 then contractionWidths r R i else fun _ => 2*r+(i : β€)*R | |
| def P (r R : β€) (i : β) : Set Vertex := Rect (routeCenter r i) (routeWidths r R i) | |
| @[simp] theorem axisCenter_zero : axisCenter 0 = 0 := by ext i; simp [axisCenter] | |
| theorem routeCenter_translation {r : β€} {i : β} (hi : 3 β€ i) (hi' : i β€ 12) : | |
| routeCenter r i = axisCenter (2*r*(i-3 : β)) := by | |
| by_cases h : i β€ 3 | |
| Β· have : i = 3 := by omega | |
| subst i | |
| simp [routeCenter] | |
| Β· simp [routeCenter,h,hi'] | |
| theorem routeWidths_translation {r R : β€} {i : β} (hi : 3 β€ i) : | |
| routeWidths r R i = fun _ => 2*r+(i : β€)*R := by | |
| by_cases h : i β€ 3 | |
| Β· have : i = 3 := by omega | |
| subst i | |
| funext j | |
| simp [routeWidths,contractionWidths,j.isLt] | |
| Β· simp [routeWidths,h] | |
| def stepSize (r : β€) (i : β) : β€ := if i < 12 then 2*r else 2*r+1 | |
| theorem routeCenter_next {r : β€} {i : β} (hi : 3 β€ i) (hi' : i β€ 12) : | |
| routeCenter r (i+1) = axisCenter (2*r*(i-3 : β)+stepSize r i) := by | |
| by_cases h : i < 12 | |
| Β· rw [routeCenter_translation (by omega) (by omega)] | |
| congr 1 | |
| simp only [stepSize,h,ite_true,Nat.cast_sub (by omega : 3 β€ i), | |
| Nat.cast_sub (by omega : 3 β€ i+1),Nat.cast_add,Nat.cast_one] | |
| ring | |
| Β· have : i = 12 := by omega | |
| subst i | |
| simp only [routeCenter,show Β¬13 β€ 3 by omega,ite_false,show Β¬13 β€ 12 by omega, | |
| stepSize,lt_self_iff_false] | |
| congr 1 | |
| norm_num | |
| ring | |
| theorem thirteen_interfaces {r R : β€} (hR : 0 < R) (hr : 100*(R+1) < r) | |
| {i : β} (hi : i < 13) : | |
| HasInterface r R (routeCenter r i) (routeWidths r R i) (P r R (i+1)) := by | |
| by_cases hi3 : i < 3 | |
| Β· simpa only [P,routeCenter,routeWidths,show i β€ 3 by omega,show i+1 β€ 3 by omega, | |
| ite_true] using contraction_interface hR hr hi3 | |
| Β· have hil : 3 β€ i := by omega | |
| have hii : i β€ 12 := by omega | |
| rw [routeCenter_translation hil hii,routeWidths_translation hil] | |
| unfold P | |
| rw [routeCenter_next hil hii,routeWidths_translation (by omega)] | |
| let a : β€ := 2*r*(i-3 : β) | |
| let w : β€ := 2*r+(β(i+1) : β€)*R | |
| have hir : (i : β€) β€ 12 := by exact_mod_cast hii | |
| have hilr : (3 : β€) β€ i := by exact_mod_cast hil | |
| have hr0 : 0 β€ r := by omega | |
| have ha0 : 0 β€ a := by dsimp [a]; positivity | |
| have ha : a β€ 18*r := by | |
| dsimp [a] | |
| rw [Nat.cast_sub hil] | |
| norm_num | |
| nlinarith | |
| have hw : w β€ 2*r+13*R := by dsimp [w]; nlinarith | |
| have hs : stepSize r i = 2*r β¨ stepSize r i = 2*r+1 := by | |
| unfold stepSize; split_ifs <;> simp | |
| have hsw : stepSize r i β€ w := by | |
| dsimp [w] | |
| rcases hs with h|h <;> rw [h] <;> nlinarith | |
| have he : (fun _ : Fin 3 => 2*r+(i : β€)*R) = fun _ => w-R := by | |
| funext j | |
| dsimp [w] | |
| ring | |
| rw [he] | |
| exact translation_interface hR hr ha0 ha hw hs hsw | |
| @[simp] theorem P_zero (r R : β€) : P r R 0 = Cube 0 (4*r) := by | |
| simp only [P,routeCenter,routeWidths,Nat.zero_le,show 0 β€ 3 by omega,ite_true,Cube] | |
| congr 1 | |
| funext i | |
| simp [contractionWidths] | |
| theorem P_thirteen_subset {r R : β€} (_hR : 0 < R) (hr : 100*(R+1) < r) : | |
| P r R 13 β Cube (axisCenter (20*r+1)) (4*r) := by | |
| intro x hx i | |
| have h := hx i | |
| simp only [routeCenter,routeWidths,show Β¬13 β€ 3 by omega,ite_false, | |
| show Β¬13 β€ 12 by omega] at h | |
| change |x i-axisCenter (20*r+1) i| β€ 4*r | |
| dsimp at h | |
| omega | |
| theorem expanded_route_subset_prism {r R : β€} (hR : 0 < R) (hr : 100*(R+1) < r) | |
| {i : β} (hi : i < 13) : | |
| Expand (routeCenter r i) (routeWidths r R i) R β Prism r := by | |
| intro u hu | |
| obtain β¨s,hs,hsub,_β© := thirteen_interfaces hR hr hi u hu | |
| apply hsub | |
| intro j | |
| change |u j-u j| β€ s | |
| simp only [sub_self,abs_zero] | |
| simp only [Set.mem_insert_iff,Set.mem_singleton_iff] at hs | |
| rcases hs with rfl|rfl|rfl <;> omega | |
| end LatticeRelay | |
| end OAI | |