import YM.Cells.Proximity /-! # Subdividing link tilings and retaining margins Use one coarse array for the replica estimate, with a finer (aligned) tiling for the *replication roots* of groups of exterior fields. Offsets are chosen on the native torus. The seam conventions and reflections, in particular `-1` in the residue formula, are link-seam conventions. No lower bound on the finer width besides positive integral width is needed here. -/ set_option autoImplicit false noncomputable section namespace YM.Next.Phase open Cells Lattice Function open scoped Topology variable {n : Side} (T Y : Tiling n) /-- Margin in whichever cell contains this site (link convention in use). -/ def Inside (T : Tiling n) (K : ℕ) (x : Site n) : Prop := x ∈ T.margin (T.which x) K lemma inside_residue (h : T.kind = .link) (K : ℕ) (x : Site n) : Inside T K x ↔ ∀ a, K ≤ T.residue x a ∧ T.residue x a + K < T.side.val := by constructor · intro hx a have he := (show _ ∧ _ from hx).2 a rw [T.residual,h] at he exact he intro H refine ⟨fun a => ?_, fun a => ?_⟩ · change T.kind.Strict T.side.val (T.coordinated (T.which x) x a) rw [T.residual,h] exact Nat.mod_lt _ T.side.property rw [T.residual,h] exact H a /-- Coordinate measured from the base, as residue modulo the tile side (not modulo the torus). -/ def stripe (T : Tiling n) (x : Site n) (a : Axis) : Per T.side := T.hom (x a - T.base a) lemma stripe_val (x : Site n) (a : Axis) : (stripe T x a).val = T.residue x a := by have he : stripe T x a = ((T.grid x a : ℕ) : Per T.side) := calc _ = T.hom ((T.grid x a : ℕ) : Per n) := by rw [Tiling.grid, ZMod.natCast_zmod_val]; rfl _ = _ := map_natCast .. rw [he]; exact ZMod.val_natCast .. lemma inside_stripe (h : T.kind = .link) (K : ℕ) (x : Site n) : Inside T K x ↔ ∀ a, K ≤ (stripe T x a).val ∧ (stripe T x a).val + K < T.side.val := by simp_rw [stripe_val] exact inside_residue T h K x lemma stripe_newly (o x : Site n) (a : Axis) : stripe (T.newly o) x a = T.hom (x a - o a) := rfl lemma shared_cell (offset : Y.base = T.base) (tiles : Y.side.val ∣ T.side.val) {x y : Site n} (e : Y.which x = Y.which y) : T.which x = T.which y := by obtain ⟨c,H⟩ := tiles funext i have hh : Y.whole x i = Y.whole y i := by rw [← Y.axis_whole, ← Y.axis_whole,e] have he (x : Site n) : T.whole x i = Y.whole x i / c := by rw [Tiling.whole, H] rw [Tiling.whole, Nat.div_div_eq_div_mul, Tiling.grid, Tiling.grid,offset] apply ZMod.val_injective T.period.val rw [T.axis_whole, T.axis_whole, he, he, hh] private lemma remainder_room {K C a b u : ℕ} (h : C=a*b) (hu : u x.val) hf).trans (ZMod.val_natCast_of_lt hp) rw [hv] dsimp only [c] at *; omega /-- Given any desired base, a translation by *less than one tile side* suffices to fit the specified fields: only base residues matter. -/ lemma shift_into {ι : Type*} [Fintype ι] (y : ι → Site n) (o : Site n) (ty : Y.kind=.link) (K : ℕ) (hk : 0 < K) (h : Fintype.card ι*(2*K) ↑(Y.hom (b a-o a)).val have he (x : Site n) (a : Axis) : stripe (Y.newly (o + wrap n w)) x a = stripe (Y.newly b) x a := by rw [stripe_newly,stripe_newly,Pi.add_apply] rw [map_sub,map_add] change Y.hom (x a) - (Y.hom (o a) + Y.hom ((w a:ℤ):Per n)) = _ rw [map_intCast]; unfold w rw [Int.cast_natCast,ZMod.natCast_zmod_val,map_sub,map_sub] abel refine ⟨w,fun a => ?_,fun i => ?_⟩ · change Int.natAbs (↑(Y.hom (b a-o a)).val : ℤ) < _ rw [Int.natAbs_natCast]; exact ZMod.val_lt _ have hx : Inside (Y.newly b) K (y i) := by unfold Inside simpa using hb (f i) rw [inside_stripe (Y.newly (o+wrap n w)) ty] simp_rw [he]; exact (inside_stripe (Y.newly b) ty _ _).mp hx end YM.Next.Phase