Download data/lean/OAI/MathematicalPhysics/AlternatingFlow/Names.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.76 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/AlternatingFlow/Names.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/MathematicalPhysics/AlternatingFlow/Names.lean
-
curl -L -o Names.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/MathematicalPhysics/AlternatingFlow/Names.lean
8.76 kB
| import OAI.MathematicalPhysics.AlternatingFlow.DerivativeBounds | |
| import OAI.MathematicalPhysics.AlternatingFlow.Arithmetic | |
| namespace OAI | |
| section NamesDevelopment | |
| open scoped BigOperators Topology ContDiff | |
| open Filter | |
| namespace AlternatingNS.Effective | |
| attribute [local instance] Arithmetic.rationalCoding | |
| def tolerance (n : β) : β := (1 / 2 : β) ^ n | |
| lemma tolerance_cast (n : β) : (tolerance n : β) = dyadicError n := by | |
| simp [tolerance, dyadicError] | |
| lemma tolerance_primrec : Primrec tolerance := | |
| Arithmetic.rat_pow.comp (Primrec.const (1 / 2)) Primrec.id | |
| lemma tolerance_pos (n : β) : (0 : β) < tolerance n := by | |
| rw [tolerance_cast]; exact pow_pos (by norm_num) _ | |
| lemma tolerance_tendsto : Tendsto (fun n => (tolerance n : β)) atTop (π 0) := by | |
| simp only [tolerance_cast, dyadicError] | |
| exact tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num) | |
| def Named {A : Type*} [Primcodable A] (f : A β β) : Prop := | |
| β a : A Γ β β β, Computable a β§ | |
| β x n, |f x - (a (x,n) : β)| β€ tolerance n | |
| lemma computable_find {A : Type*} [Primcodable A] (p : A β β β Prop) | |
| [DecidableRel p] (hp : Computable (fun z : A Γ β => decide (p z.1 z.2))) | |
| (h : β a, β n, p a n) : Computable (fun a => @Nat.find (p a) (fun _ => inferInstance) (h a)) := by | |
| have hr : Partrec (fun a => Nat.rfind (fun n => Part.some (decide (p a n)))) := | |
| Partrec.rfind hp.toβ.partrecβ | |
| apply hr.of_eq_tot | |
| intro a | |
| apply Nat.mem_rfind.mpr | |
| refine β¨?_, fun {m} hm => ?_β© | |
| Β· simp [Nat.find_spec (h a)] | |
| Β· simp [Nat.find_min (h a) hm] | |
| lemma Named.of_certificate {A : Type*} [Primcodable A] (f : A β β) | |
| (a e : A Γ β β β) (ha : Computable a) (he : Computable e) | |
| (hbound : β x n, |f x - (a (x,n) : β)| β€ (e (x,n) : β)) | |
| (hlim : β x, Tendsto (fun n => (e (x,n) : β)) atTop (π 0)) : Named f := by | |
| classical | |
| let p (z : A Γ β) (n : β) : Prop := e (z.1,n) β€ tolerance z.2 | |
| have hp : Computable (fun z : (A Γ β) Γ β => decide (p z.1 z.2)) := | |
| Arithmetic.rat_le.decide.to_comp.comp | |
| (he.comp ((Computable.fst.comp Computable.fst).pair Computable.snd)) | |
| (tolerance_primrec.to_comp.comp (Computable.snd.comp Computable.fst)) | |
| have hex (z : A Γ β) : β n, p z n := by | |
| have hE := (hlim z.1).eventually (gt_mem_nhds (tolerance_pos z.2)) | |
| obtain β¨n,hnβ© := hE.exists | |
| exact β¨n, by exact_mod_cast hn.leβ© | |
| let N (z : A Γ β) : β := Nat.find (hex z) | |
| have hN : Computable N := computable_find p hp hex | |
| refine β¨fun z => a (z.1,N z), ha.comp (Computable.fst.pair hN), fun x k => ?_β© | |
| exact (hbound x (N (x,k))).trans (by exact_mod_cast Nat.find_spec (hex (x,k))) | |
| lemma Named.congr {A : Type*} [Primcodable A] {f g : A β β} | |
| (hf : Named f) (h : β a, f a = g a) : Named g := by | |
| simpa only [show f = g from funext h] using hf | |
| lemma Named.comp {A B : Type*} [Primcodable A] [Primcodable B] {f : A β β} | |
| (hf : Named f) {g : B β A} (hg : Computable g) : Named (f β g) := by | |
| obtain β¨a, ha, hbβ© := hf | |
| exact β¨fun z => a (g z.1,z.2), | |
| ha.comp ((hg.comp Computable.fst).pair Computable.snd), fun z n => hb (g z) nβ© | |
| lemma Named.rational {A : Type*} [Primcodable A] {f : A β β} (hf : Computable f) : | |
| Named (fun a => (f a : β)) := | |
| β¨fun z => f z.1, hf.comp Computable.fst, fun _ n => by | |
| simp only [sub_self, abs_zero]; exact (tolerance_pos n).leβ© | |
| lemma Named.const {A : Type*} [Primcodable A] (q : β) : Named (fun _ : A => (q : β)) := | |
| Named.rational (Computable.const q) | |
| lemma approximation_tendsto {x : β} {a : β β β} | |
| (h : β n, |x - (a n : β)| β€ tolerance n) : | |
| Tendsto (fun n => (a n : β)) atTop (π x) := by | |
| apply tendsto_of_tendsto_of_tendsto_of_le_of_le (g := fun n => x - (tolerance n : β)) | |
| (h := fun n => x + (tolerance n : β)) | |
| Β· simpa using tendsto_const_nhds.sub tolerance_tendsto | |
| Β· simpa using tendsto_const_nhds.add tolerance_tendsto | |
| Β· intro n; have := (abs_le.mp (h n)).2; linarith | |
| Β· intro n; have := (abs_le.mp (h n)).1; linarith | |
| lemma Named.add {A : Type*} [Primcodable A] {f g : A β β} | |
| (hf : Named f) (hg : Named g) : Named (fun x => f x + g x) := by | |
| obtain β¨a,ha,haeβ© := hf | |
| obtain β¨b,hb,hbeβ© := hg | |
| apply Named.of_certificate _ (fun z => a z + b z) (fun z => 2 * tolerance z.2) | |
| (Arithmetic.rat_add.to_comp.comp ha hb) | |
| (Arithmetic.rat_mul.to_comp.comp (Computable.const 2) | |
| (tolerance_primrec.to_comp.comp Computable.snd)) | |
| Β· intro x n | |
| push_cast | |
| calc | |
| _ = |(f x - (a (x,n) : β)) + (g x - (b (x,n) : β))| := by congr 1; ring | |
| _ β€ _ := (abs_add_le _ _).trans (by linarith [hae x n, hbe x n]) | |
| Β· intro x; simpa using (tolerance_tendsto.const_mul 2) | |
| lemma Named.neg {A : Type*} [Primcodable A] {f : A β β} (hf : Named f) : | |
| Named (fun x => -f x) := by | |
| obtain β¨a,ha,hβ© := hf | |
| refine β¨fun z => -a z, Arithmetic.rat_neg.to_comp.comp ha, fun x n => ?_β© | |
| simpa only [Rat.cast_neg, neg_sub_neg, abs_sub_comm] using h x n | |
| lemma Named.sub {A : Type*} [Primcodable A] {f g : A β β} | |
| (hf : Named f) (hg : Named g) : Named (fun x => f x - g x) := | |
| (hf.add hg.neg).congr (fun _ => (sub_eq_add_neg _ _).symm) | |
| lemma Named.mul {A : Type*} [Primcodable A] {f g : A β β} | |
| (hf : Named f) (hg : Named g) : Named (fun x => f x * g x) := by | |
| obtain β¨a,ha,haeβ© := hf | |
| obtain β¨b,hb,hbeβ© := hg | |
| let e : A Γ β β β := fun z => (|a z| + |b z| + tolerance z.2) * tolerance z.2 | |
| have he : Computable e := Arithmetic.rat_mul.to_comp.comp | |
| (Arithmetic.rat_add.to_comp.comp | |
| (Arithmetic.rat_add.to_comp.comp (Arithmetic.rat_abs.to_comp.comp ha) | |
| (Arithmetic.rat_abs.to_comp.comp hb)) | |
| (tolerance_primrec.to_comp.comp Computable.snd)) | |
| (tolerance_primrec.to_comp.comp Computable.snd) | |
| apply Named.of_certificate _ (fun z => a z * b z) e | |
| (Arithmetic.rat_mul.to_comp.comp ha hb) he | |
| Β· intro x n | |
| dsimp [e]; push_cast | |
| have hf : |f x| β€ |(a (x,n) : β)| + (tolerance n : β) := by | |
| have h := abs_add_le (f x - (a (x,n) : β)) (a (x,n)) | |
| ring_nf at h | |
| linarith [hae x n] | |
| calc | |
| _ = |f x * (g x - (b (x,n) : β)) + (f x - (a (x,n) : β)) * (b (x,n) : β)| := by congr 1; ring | |
| _ β€ |f x| * |g x - (b (x,n) : β)| + |f x - (a (x,n) : β)| * |(b (x,n) : β)| := by | |
| simpa only [abs_mul] using abs_add_le (f x * (g x - (b (x,n) : β))) ((f x - (a (x,n) : β)) * (b (x,n) : β)) | |
| _ β€ (|(a (x,n) : β)| + (tolerance n : β)) * (tolerance n : β) + | |
| (tolerance n : β) * |(b (x,n) : β)| := | |
| add_le_add (mul_le_mul hf (hbe x n) (abs_nonneg _) (add_nonneg (abs_nonneg _) (tolerance_pos n).le)) | |
| (mul_le_mul_of_nonneg_right (hae x n) (abs_nonneg _)) | |
| _ = _ := by ring | |
| Β· intro x | |
| dsimp [e] | |
| simp only [Rat.cast_mul, Rat.cast_add, Rat.cast_abs] | |
| simpa using (((approximation_tendsto (hae x)).abs.add | |
| (approximation_tendsto (hbe x)).abs).add tolerance_tendsto).mul tolerance_tendsto | |
| lemma Named.ite {A : Type*} [Primcodable A] (p : A β Prop) [DecidablePred p] | |
| (hp : Computable (fun a => decide (p a))) {f g : A β β} | |
| (hf : Named f) (hg : Named g) : Named (fun x => if p x then f x else g x) := by | |
| obtain β¨a,ha,haeβ© := hf | |
| obtain β¨b,hb,hbeβ© := hg | |
| refine β¨fun z => if p z.1 then a z else b z, | |
| (Computable.cond (hp.comp Computable.fst) ha hb).of_eq (by simp), ?_β© | |
| intro x n; dsimp only; split_ifs <;> simp_all | |
| lemma Named.apply_lipschitz {A : Type*} [Primcodable A] (g : A β β β β) | |
| (L : A β β) (hL : Computable L) (hpos : β a, 0 β€ L a) | |
| (hLip : β a x y, |g a x - g a y| β€ (L a : β) * |x - y|) | |
| (hg : Named (fun z : A Γ β => g z.1 z.2)) | |
| {f : A β β} (hf : Named f) : Named (fun a => g a (f a)) := by | |
| obtain β¨a,ha,haeβ© := hf | |
| obtain β¨b,hb,hbeβ© := hg | |
| apply Named.of_certificate _ (fun z => b ((z.1,a z),z.2)) | |
| (fun z => (L z.1 + 1) * tolerance z.2) | |
| (hb.comp ((Computable.fst.pair ha).pair Computable.snd)) | |
| (Arithmetic.rat_mul.to_comp.comp | |
| (Arithmetic.rat_add.to_comp.comp (hL.comp Computable.fst) (Computable.const 1)) | |
| (tolerance_primrec.to_comp.comp Computable.snd)) | |
| Β· intro x n | |
| push_cast | |
| calc | |
| _ β€ |g x (f x) - g x (a (x,n))| + |g x (a (x,n)) - (b ((x,a (x,n)),n) : β)| := abs_sub_le _ _ _ | |
| _ β€ (L x : β) * (tolerance n : β) + (tolerance n : β) := | |
| add_le_add ((hLip x _ _).trans (mul_le_mul_of_nonneg_left (hae x n) (by exact_mod_cast hpos x))) | |
| (hbe (x,a (x,n)) n) | |
| _ = _ := by ring | |
| Β· intro x; simpa using tolerance_tendsto.const_mul ((L x : β) + 1) | |
| end AlternatingNS.Effective | |
| end NamesDevelopment | |
| end OAI | |