Download data/lean/OAI/MathematicalPhysics/AlternatingFlow/Encoding.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/AlternatingFlow/Encoding.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/MathematicalPhysics/AlternatingFlow/Encoding.lean
-
curl -L -o Encoding.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/AlternatingFlow/Encoding.lean
11.2 kB
| import OAI.MathematicalPhysics.AlternatingFlow.Scales | |
| namespace OAI | |
| open scoped BigOperators ENNReal NNReal Topology ContDiff | |
| open MeasureTheory | |
| namespace AlternatingNS | |
| namespace Encoding | |
| noncomputable def code (b : β) : List β β β | |
| | [] => 0 | |
| | d :: ds => ((d : β) + code b ds) / b | |
| noncomputable def tailMax (b : β) : β := | |
| letI := twoAtLeastTwo | |
| ((b : β) - 2) / ((b : β) - 1) | |
| lemma tailMax_nonneg (b : β) (hb : 2 β€ b) : 0 β€ tailMax b := by | |
| have hb' : (2 : β) β€ b := by exact_mod_cast hb | |
| unfold tailMax | |
| exact div_nonneg (by linarith) (by linarith) | |
| lemma tailMax_lt_one (b : β) (hb : 2 β€ b) : tailMax b < 1 := by | |
| have hb' : (2 : β) β€ b := by exact_mod_cast hb | |
| unfold tailMax | |
| apply (div_lt_one (by linarith)).2 | |
| linarith | |
| lemma tailMax_identity (b : β) (hb : 2 β€ b) : | |
| (b : β) * tailMax b = (b : β) - 2 + tailMax b := by | |
| have hb' : (2 : β) β€ b := by exact_mod_cast hb | |
| have h : (b : β) - 1 β 0 := by linarith | |
| unfold tailMax | |
| field_simp | |
| ring | |
| lemma code_nonneg (b : β) (L : List β) : 0 β€ code b L := by | |
| induction L with | |
| | nil => simp [code] | |
| | cons d L ih => simpa only [code] using div_nonneg (by positivity) (Nat.cast_nonneg b) | |
| lemma code_le_tailMax (b : β) (hb : 2 β€ b) (L : List β) | |
| (hL : β d β L, d + 2 β€ b) : code b L β€ tailMax b := by | |
| have hb' : (0 : β) < b := by exact_mod_cast (show 0 < b by omega) | |
| induction L with | |
| | nil => exact tailMax_nonneg b hb | |
| | cons d L ih => | |
| have hd : (d : β) + 2 β€ b := by exact_mod_cast hL d (by simp) | |
| have ht : code b L β€ tailMax b := ih (fun a ha => hL a (List.mem_cons_of_mem d ha)) | |
| rw [code, div_le_iffβ hb'] | |
| have hi := tailMax_identity b hb | |
| linarith | |
| lemma digit_interval (b d : β) (hb : 2 β€ b) (L : List β) | |
| (hL : β a β L, a + 2 β€ b) : | |
| (d : β) / b β€ code b (d :: L) β§ code b (d :: L) β€ ((d : β) + 1) / b := by | |
| have hb' : (0 : β) < b := by exact_mod_cast (show 0 < b by omega) | |
| constructor | |
| Β· exact div_le_div_of_nonneg_right (le_add_of_nonneg_right (code_nonneg b L)) hb'.le | |
| Β· apply div_le_div_of_nonneg_right _ hb'.le | |
| linarith [code_le_tailMax b hb L hL, tailMax_lt_one b hb] | |
| lemma code_append (b : β) (hb : 0 < b) (L R : List β) : | |
| code b (L ++ R) = code b L + ((b : β) ^ L.length)β»ΒΉ * code b R := by | |
| have hb' : (b : β) β 0 := by exact_mod_cast (ne_of_gt hb) | |
| induction L with | |
| | nil => simp [code] | |
| | cons d L ih => | |
| simp only [List.cons_append, code, List.length_cons, pow_succ, ih] | |
| field_simp | |
| ring | |
| lemma code_denominator (b : β) (hb : 0 < b) (L : List β) : | |
| β a : β, (b : β) ^ L.length * code b L = a := by | |
| have hb' : (b : β) β 0 := by exact_mod_cast (ne_of_gt hb) | |
| induction L with | |
| | nil => exact β¨0, by simp [code]β© | |
| | cons d L ih => | |
| obtain β¨a, haβ© := ih | |
| refine β¨b ^ L.length * d + a, ?_β© | |
| calc | |
| (b : β) ^ (d :: L).length * code b (d :: L) = | |
| (b : β) ^ L.length * d + (b : β) ^ L.length * code b L := by | |
| simp only [List.length_cons, code, pow_succ] | |
| field_simp | |
| _ = ((b ^ L.length * d + a : β) : β) := by rw [ha]; push_cast; rfl | |
| lemma configuration_block (b g : β) (hb : 0 < b) (L R : List β) : | |
| code b (g :: (L ++ R)) = | |
| ((g : β) + code b L + ((b : β) ^ L.length)β»ΒΉ * code b R) / b := by | |
| rw [code, code_append b hb] | |
| ring | |
| lemma integral_rescale (b k l : β) (hkl : k β€ l) {x : β} | |
| (hx : β a : β€, (b : β) ^ k * x = a) : | |
| β a : β€, (b : β) ^ l * x = a := by | |
| obtain β¨a, haβ© := hx | |
| refine β¨(b : β€) ^ (l - k) * a, ?_β© | |
| calc | |
| (b : β) ^ l * x = (b : β) ^ (l - k) * ((b : β) ^ k * x) := by | |
| rw [β mul_assoc, β pow_add, Nat.sub_add_cancel hkl] | |
| _ = ((b : β€) ^ (l - k) * a : β€) := by rw [ha]; push_cast; rfl | |
| lemma sum_integral {ΞΉ : Type*} (S : Finset ΞΉ) (f : ΞΉ β β) | |
| (hf : β i β S, β a : β€, f i = a) : β a : β€, β i β S, f i = a := by | |
| classical | |
| induction S using Finset.induction_on with | |
| | empty => exact β¨0, by simpβ© | |
| | @insert i S hi ih => | |
| obtain β¨a, haβ© := hf i (by simp) | |
| obtain β¨c, hcβ© := ih (fun j hj => hf j (by simp [hj])) | |
| exact β¨a + c, by simp [Finset.sum_insert hi, ha, hc]β© | |
| noncomputable def donor (b N : β) (C : β β β) (n : β) : β := | |
| β j β Finset.range (n + 1), if j % 2 = n % 2 then Scales.Ξ΅ b N j * C j else 0 | |
| lemma old_record_integral (b N j n : β) (hb : 0 < b) (hjn : j < n) {C : β} | |
| (hC : β a : β€, (b : β) ^ (1 + 2 * Scales.K N j) * C = a) : | |
| β a : β€, (b : β) ^ Scales.s N n * (Scales.Ξ΅ b N j * C) = a := by | |
| apply integral_rescale b (Scales.s N j + (1 + 2 * Scales.K N j)) | |
| (Scales.s N n) (Scales.old_scale_gap N j n hjn) | |
| obtain β¨a, haβ© := hC | |
| refine β¨a, ?_β© | |
| have hb' : (b : β) β 0 := by exact_mod_cast (ne_of_gt hb) | |
| calc | |
| (b : β) ^ (Scales.s N j + (1 + 2 * Scales.K N j)) * (Scales.Ξ΅ b N j * C) = | |
| (b : β) ^ (1 + 2 * Scales.K N j) * C := by | |
| dsimp [Scales.Ξ΅] | |
| rw [pow_add] | |
| field_simp | |
| _ = a := ha | |
| lemma donor_integer_add (b N n : β) (hb : 0 < b) (C : β β β) | |
| (hC : β j, β a : β€, (b : β) ^ (1 + 2 * Scales.K N j) * C j = a) : | |
| β a : β€, (b : β) ^ Scales.s N n * donor b N C n = a + C n := by | |
| have hI : β j β Finset.range n, | |
| β a : β€, (b : β) ^ Scales.s N n * | |
| (if j % 2 = n % 2 then Scales.Ξ΅ b N j * C j else 0) = a := by | |
| intro j hj | |
| split_ifs | |
| Β· exact old_record_integral b N j n hb (Finset.mem_range.1 hj) (hC j) | |
| Β· exact β¨0, by simpβ© | |
| obtain β¨a, haβ© := sum_integral (Finset.range n) _ hI | |
| refine β¨a, ?_β© | |
| have hb' : (b : β) β 0 := by exact_mod_cast (ne_of_gt hb) | |
| rw [donor, Finset.sum_range_succ] | |
| simp only [ite_true, mul_add, Finset.mul_sum] | |
| rw [ha] | |
| dsimp [Scales.Ξ΅] | |
| field_simp | |
| def DecoderLaw (b : β) (P : β β β) : Prop := | |
| Function.Periodic P 1 β§ β v β Set.Icc 0 (tailMax b), P v = v | |
| lemma decoder_int_add (b : β) (P : β β β) (hP : DecoderLaw b P) | |
| (a : β€) (v : β) (hv : v β Set.Icc 0 (tailMax b)) : P ((a : β) + v) = v := by | |
| have h := hP.1.int_mul a v | |
| simpa only [mul_one, add_comm, hP.2 v hv] using h | |
| lemma read_current (b N n : β) (hb : 2 β€ b) (C : β β β) | |
| (hC : β j, β a : β€, (b : β) ^ (1 + 2 * Scales.K N j) * C j = a) | |
| (hc : C n β Set.Icc 0 (tailMax b)) | |
| (P : β β β) (hP : DecoderLaw b P) : | |
| P ((b : β) ^ Scales.s N n * donor b N C n) = C n := by | |
| obtain β¨a, haβ© := donor_integer_add b N n (by omega) C hC | |
| rw [ha] | |
| exact decoder_int_add b P hP a (C n) hc | |
| lemma remove_prefix (b s : β) (hb : 0 < b) (L R : List β) (D : β) | |
| (hD : β a : β€, (b : β) ^ s * D = a + code b (L ++ R)) : | |
| β a : β€, (b : β) ^ (s + L.length) * D = a + code b R := by | |
| obtain β¨a, haβ© := hD | |
| obtain β¨c, hcβ© := code_denominator b hb L | |
| refine β¨(b : β€) ^ L.length * a + c, ?_β© | |
| have hb' : (b : β) β 0 := by exact_mod_cast (ne_of_gt hb) | |
| calc | |
| (b : β) ^ (s + L.length) * D = (b : β) ^ L.length * ((b : β) ^ s * D) := by | |
| rw [pow_add]; ring | |
| _ = (b : β) ^ L.length * a + (b : β) ^ L.length * code b L + code b R := by | |
| rw [ha, code_append b hb] | |
| field_simp | |
| ring | |
| _ = (((b : β€) ^ L.length * a + c : β€) : β) + code b R := by rw [hc]; push_cast; rfl | |
| lemma read_after_prefix (b s : β) (hb : 2 β€ b) (L R : List β) (D : β) | |
| (hD : β a : β€, (b : β) ^ s * D = a + code b (L ++ R)) | |
| (hR : β d β R, d + 2 β€ b) (P : β β β) (hP : DecoderLaw b P) : | |
| P ((b : β) ^ (s + L.length) * D) = code b R := by | |
| obtain β¨a, haβ© := remove_prefix b s (by omega) L R D hD | |
| rw [ha] | |
| exact decoder_int_add b P hP a _ β¨code_nonneg b R, code_le_tailMax b hb R hRβ© | |
| lemma read_configuration (b s g : β) (hb : 2 β€ b) (L R : List β) (D : β) | |
| (hD : β a : β€, (b : β) ^ s * D = a + code b (g :: (L ++ R))) | |
| (hd : β d β g :: (L ++ R), d + 2 β€ b) | |
| (P : β β β) (hP : DecoderLaw b P) : | |
| P ((b : β) ^ s * D) = code b (g :: (L ++ R)) β§ | |
| P ((b : β) ^ (s + 1 + L.length) * D) = code b R β§ | |
| P ((b : β) ^ (s + 1) * D) - ((b : β) ^ L.length)β»ΒΉ * | |
| P ((b : β) ^ (s + 1 + L.length) * D) = code b L := by | |
| have hLR : β d β L ++ R, d + 2 β€ b := | |
| fun d h => hd d (List.mem_cons_of_mem g h) | |
| have hR : β d β R, d + 2 β€ b := fun d h => hLR d (List.mem_append_right L h) | |
| have hβ := read_after_prefix b s hb [g] (L ++ R) D hD hLR P hP | |
| have hβ := read_after_prefix b s hb (g :: L) R D (by simpa using hD) hR P hP | |
| simp only [List.length_cons, List.length_nil] at hβ hβ | |
| have hβ' : P ((b : β) ^ (s + 1 + L.length) * D) = code b R := by | |
| simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using hβ | |
| refine β¨?_, hβ', ?_β© | |
| Β· obtain β¨a, haβ© := hD | |
| rw [ha] | |
| exact decoder_int_add b P hP a _ | |
| β¨code_nonneg b _, code_le_tailMax b hb _ hdβ© | |
| Β· rw [hβ, hβ', code_append b (by omega)] | |
| ring | |
| end Encoding | |
| end AlternatingNS | |
| namespace AlternatingNS | |
| namespace Encoding | |
| lemma donor_in_plateau (b N n : β) (hb : 4 β€ b) (C : β β β) | |
| (hC : β j, C j β Set.Icc (0 : β) 1) : | |
| donor b N C n β Set.Ico (0 : β) (1 / 4) := by | |
| have hterm : β j : β, | |
| 0 β€ (if j % 2 = n % 2 then Scales.Ξ΅ b N j * C j else 0) β§ | |
| (if j % 2 = n % 2 then Scales.Ξ΅ b N j * C j else 0) β€ Scales.Ξ΅ b N j := by | |
| intro j | |
| have hΞ΅ := Scales.Ξ΅_nonneg b N j (by omega) | |
| split_ifs | |
| Β· exact β¨mul_nonneg hΞ΅ (hC j).1, mul_le_of_le_one_right hΞ΅ (hC j).2β© | |
| Β· exact β¨le_rfl, hΞ΅β© | |
| constructor | |
| Β· apply Finset.sum_nonneg | |
| intro j _ | |
| exact (hterm j).1 | |
| Β· apply lt_of_le_of_lt _ (Scales.initial_memory_small b N hb) | |
| apply le_trans _ (Scales.total_memory_le b N (by omega)) | |
| calc | |
| donor b N C n β€ β j β Finset.range (n + 1), Scales.Ξ΅ b N j := | |
| Finset.sum_le_sum (fun j _ => (hterm j).2) | |
| _ β€ β' j : β, Scales.Ξ΅ b N j := | |
| (Scales.summable_Ξ΅ b N (by omega)).sum_le_tsum _ | |
| (fun j _ => Scales.Ξ΅_nonneg b N j (by omega)) | |
| lemma pop_code (b d : β) (hb : 0 < b) (L : List β) : | |
| (b : β) * code b (d :: L) - d = code b L := by | |
| have hb' : (b : β) β 0 := by exact_mod_cast (ne_of_gt hb) | |
| dsimp [code] | |
| field_simp | |
| ring | |
| lemma tape_step_right (b a w : β) (hb : 0 < b) (L R : List β) : | |
| (((w : β) + code b L) / b, (b : β) * code b (a :: R) - a) = | |
| (code b (w :: L), code b R) := by | |
| rw [pop_code b a hb R] | |
| rfl | |
| lemma tape_step_stay (b a w : β) (hb : 0 < b) (L R : List β) : | |
| (code b L, ((w : β) + ((b : β) * code b (a :: R) - a)) / b) = | |
| (code b L, code b (w :: R)) := by | |
| rw [pop_code b a hb R] | |
| rfl | |
| lemma tape_step_left (b a w l : β) (hb : 0 < b) (L R : List β) : | |
| ((b : β) * code b (l :: L) - l, | |
| ((l : β) + ((w : β) + ((b : β) * code b (a :: R) - a)) / b) / b) = | |
| (code b L, code b (l :: w :: R)) := by | |
| rw [pop_code b l hb L, pop_code b a hb R] | |
| rfl | |
| end Encoding | |
| end AlternatingNS | |
| end OAI | |