state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
๐•œโœ : Type u_1 instโœโต : NontriviallyNormedField ๐•œโœ Eโœ : Type u_2 instโœโด : SeminormedAddCommGroup Eโœ instโœยณ : NormedSpace ๐•œโœ Eโœ ๐•œ : Type u_3 E : Type u_4 instโœยฒ : IsROrC ๐•œ instโœยน : NormedAddCommGroup E instโœ : NormedSpace ๐•œ E r : โ„ hr : 0 < r x' : Dual ๐•œ E h : x' โˆˆ polar ๐•œ (closedBall 0 r) โŠข โ€–x'โ€– โ‰ค rโปยน
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.IsROrC import Mathlib.Analysis.LocallyConvex.Polar #align_import analysis.normed_space.dual from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The topological dual of a normed space In this file we define the topological dual `NormedSpace.Dual` of a normed space, and the continuous linear map `NormedSpace.inclusionInDoubleDual` from a normed space into its double dual. For base field `๐•œ = โ„` or `๐•œ = โ„‚`, this map is actually an isometric embedding; we provide a version `NormedSpace.inclusionInDoubleDualLi` of the map which is of type a bundled linear isometric embedding, `E โ†’โ‚—แตข[๐•œ] (Dual ๐•œ (Dual ๐•œ E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `SeminormedAddCommGroup` and we specialize to `NormedAddCommGroup` when needed. ## Main definitions * `inclusionInDoubleDual` and `inclusionInDoubleDualLi` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals `x'` for which `โ€–x' zโ€– โ‰ค 1` for every `z โˆˆ s`. ## Tags dual -/ noncomputable section open Classical Topology Bornology universe u v namespace NormedSpace section General variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable (E : Type*) [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace ๐•œ F] /-- The topological dual of a seminormed space `E`. -/ abbrev Dual : Type _ := E โ†’L[๐•œ] ๐•œ #align normed_space.dual NormedSpace.Dual -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_eq until -- leanprover/lean4#2522 is resolved; remove once fixed instance : NormedSpace ๐•œ (Dual ๐•œ E) := inferInstance -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_le until -- leanprover/lean4#2522 is resolved; remove once fixed instance : SeminormedAddCommGroup (Dual ๐•œ E) := inferInstance /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusionInDoubleDual : E โ†’L[๐•œ] Dual ๐•œ (Dual ๐•œ E) := ContinuousLinearMap.apply ๐•œ ๐•œ #align normed_space.inclusion_in_double_dual NormedSpace.inclusionInDoubleDual @[simp] theorem dual_def (x : E) (f : Dual ๐•œ E) : inclusionInDoubleDual ๐•œ E x f = f x := rfl #align normed_space.dual_def NormedSpace.dual_def theorem inclusionInDoubleDual_norm_eq : โ€–inclusionInDoubleDual ๐•œ Eโ€– = โ€–ContinuousLinearMap.id ๐•œ (Dual ๐•œ E)โ€– := ContinuousLinearMap.op_norm_flip _ #align normed_space.inclusion_in_double_dual_norm_eq NormedSpace.inclusionInDoubleDual_norm_eq theorem inclusionInDoubleDual_norm_le : โ€–inclusionInDoubleDual ๐•œ Eโ€– โ‰ค 1 := by rw [inclusionInDoubleDual_norm_eq] exact ContinuousLinearMap.norm_id_le #align normed_space.inclusion_in_double_dual_norm_le NormedSpace.inclusionInDoubleDual_norm_le theorem double_dual_bound (x : E) : โ€–(inclusionInDoubleDual ๐•œ E) xโ€– โ‰ค โ€–xโ€– := by simpa using ContinuousLinearMap.le_of_op_norm_le _ (inclusionInDoubleDual_norm_le ๐•œ E) x #align normed_space.double_dual_bound NormedSpace.double_dual_bound /-- The dual pairing as a bilinear form. -/ def dualPairing : Dual ๐•œ E โ†’โ‚—[๐•œ] E โ†’โ‚—[๐•œ] ๐•œ := ContinuousLinearMap.coeLM ๐•œ #align normed_space.dual_pairing NormedSpace.dualPairing @[simp] theorem dualPairing_apply {v : Dual ๐•œ E} {x : E} : dualPairing ๐•œ E v x = v x := rfl #align normed_space.dual_pairing_apply NormedSpace.dualPairing_apply theorem dualPairing_separatingLeft : (dualPairing ๐•œ E).SeparatingLeft := by rw [LinearMap.separatingLeft_iff_ker_eq_bot, LinearMap.ker_eq_bot] exact ContinuousLinearMap.coe_injective #align normed_space.dual_pairing_separating_left NormedSpace.dualPairing_separatingLeft end General section BidualIsometry variable (๐•œ : Type v) [IsROrC ๐•œ] {E : Type u} [NormedAddCommGroup E] [NormedSpace ๐•œ E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `ContinuousLinearMap.op_norm_le_bound`. -/ theorem norm_le_dual_bound (x : E) {M : โ„} (hMp : 0 โ‰ค M) (hM : โˆ€ f : Dual ๐•œ E, โ€–f xโ€– โ‰ค M * โ€–fโ€–) : โ€–xโ€– โ‰ค M := by classical by_cases h : x = 0 ยท simp only [h, hMp, norm_zero] ยท obtain โŸจf, hfโ‚, hfxโŸฉ : โˆƒ f : E โ†’L[๐•œ] ๐•œ, โ€–fโ€– = 1 โˆง f x = โ€–xโ€– := exists_dual_vector ๐•œ x h calc โ€–xโ€– = โ€–(โ€–xโ€– : ๐•œ)โ€– := IsROrC.norm_coe_norm.symm _ = โ€–f xโ€– := by rw [hfx] _ โ‰ค M * โ€–fโ€– := (hM f) _ = M := by rw [hfโ‚, mul_one] #align normed_space.norm_le_dual_bound NormedSpace.norm_le_dual_bound theorem eq_zero_of_forall_dual_eq_zero {x : E} (h : โˆ€ f : Dual ๐•œ E, f x = (0 : ๐•œ)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound ๐•œ x le_rfl fun f => by simp [h f]) #align normed_space.eq_zero_of_forall_dual_eq_zero NormedSpace.eq_zero_of_forall_dual_eq_zero theorem eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 โ†” โˆ€ g : Dual ๐•œ E, g x = 0 := โŸจfun hx => by simp [hx], fun h => eq_zero_of_forall_dual_eq_zero ๐•œ hโŸฉ #align normed_space.eq_zero_iff_forall_dual_eq_zero NormedSpace.eq_zero_iff_forall_dual_eq_zero /-- See also `geometric_hahn_banach_point_point`. -/ theorem eq_iff_forall_dual_eq {x y : E} : x = y โ†” โˆ€ g : Dual ๐•œ E, g x = g y := by rw [โ† sub_eq_zero, eq_zero_iff_forall_dual_eq_zero ๐•œ (x - y)] simp [sub_eq_zero] #align normed_space.eq_iff_forall_dual_eq NormedSpace.eq_iff_forall_dual_eq /-- The inclusion of a normed space in its double dual is an isometry onto its image.-/ def inclusionInDoubleDualLi : E โ†’โ‚—แตข[๐•œ] Dual ๐•œ (Dual ๐•œ E) := { inclusionInDoubleDual ๐•œ E with norm_map' := by intro x apply le_antisymm ยท exact double_dual_bound ๐•œ E x rw [ContinuousLinearMap.norm_def] refine' le_csInf ContinuousLinearMap.bounds_nonempty _ rintro c โŸจhc1, hc2โŸฉ exact norm_le_dual_bound ๐•œ x hc1 hc2 } #align normed_space.inclusion_in_double_dual_li NormedSpace.inclusionInDoubleDualLi end BidualIsometry section PolarSets open Metric Set NormedSpace /-- Given a subset `s` in a normed space `E` (over a field `๐•œ`), the polar `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals which evaluate to something of norm at most one at all points `z โˆˆ s`. -/ def polar (๐•œ : Type*) [NontriviallyNormedField ๐•œ] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] : Set E โ†’ Set (Dual ๐•œ E) := (dualPairing ๐•œ E).flip.polar #align normed_space.polar NormedSpace.polar variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] theorem mem_polar_iff {x' : Dual ๐•œ E} (s : Set E) : x' โˆˆ polar ๐•œ s โ†” โˆ€ z โˆˆ s, โ€–x' zโ€– โ‰ค 1 := Iff.rfl #align normed_space.mem_polar_iff NormedSpace.mem_polar_iff @[simp] theorem polar_univ : polar ๐•œ (univ : Set E) = {(0 : Dual ๐•œ E)} := (dualPairing ๐•œ E).flip.polar_univ (LinearMap.flip_separatingRight.mpr (dualPairing_separatingLeft ๐•œ E)) #align normed_space.polar_univ NormedSpace.polar_univ theorem isClosed_polar (s : Set E) : IsClosed (polar ๐•œ s) := by dsimp only [NormedSpace.polar] simp only [LinearMap.polar_eq_iInter, LinearMap.flip_apply] refine' isClosed_biInter fun z _ => _ exact isClosed_Iic.preimage (ContinuousLinearMap.apply ๐•œ ๐•œ z).continuous.norm #align normed_space.is_closed_polar NormedSpace.isClosed_polar @[simp] theorem polar_closure (s : Set E) : polar ๐•œ (closure s) = polar ๐•œ s := ((dualPairing ๐•œ E).flip.polar_antitone subset_closure).antisymm <| (dualPairing ๐•œ E).flip.polar_gc.l_le <| closure_minimal ((dualPairing ๐•œ E).flip.polar_gc.le_u_l s) <| by simpa [LinearMap.flip_flip] using (isClosed_polar _ _).preimage (inclusionInDoubleDual ๐•œ E).continuous #align normed_space.polar_closure NormedSpace.polar_closure variable {๐•œ} /-- If `x'` is a dual element such that the norms `โ€–x' zโ€–` are bounded for `z โˆˆ s`, then a small scalar multiple of `x'` is in `polar ๐•œ s`. -/ theorem smul_mem_polar {s : Set E} {x' : Dual ๐•œ E} {c : ๐•œ} (hc : โˆ€ z, z โˆˆ s โ†’ โ€–x' zโ€– โ‰ค โ€–cโ€–) : cโปยน โ€ข x' โˆˆ polar ๐•œ s := by by_cases c_zero : c = 0 ยท simp only [c_zero, inv_zero, zero_smul] exact (dualPairing ๐•œ E).flip.zero_mem_polar _ have eq : โˆ€ z, โ€–cโปยน โ€ข x' zโ€– = โ€–cโปยนโ€– * โ€–x' zโ€– := fun z => norm_smul cโปยน _ have le : โˆ€ z, z โˆˆ s โ†’ โ€–cโปยน โ€ข x' zโ€– โ‰ค โ€–cโปยนโ€– * โ€–cโ€– := by intro z hzs rw [eq z] apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _) have cancel : โ€–cโปยนโ€– * โ€–cโ€– = 1 := by simp only [c_zero, norm_eq_zero, Ne.def, not_false_iff, inv_mul_cancel, norm_inv] rwa [cancel] at le #align normed_space.smul_mem_polar NormedSpace.smul_mem_polar theorem polar_ball_subset_closedBall_div {c : ๐•œ} (hc : 1 < โ€–cโ€–) {r : โ„} (hr : 0 < r) : polar ๐•œ (ball (0 : E) r) โІ closedBall (0 : Dual ๐•œ E) (โ€–cโ€– / r) := by intro x' hx' rw [mem_polar_iff] at hx' simp only [polar, mem_setOf, mem_closedBall_zero_iff, mem_ball_zero_iff] at * have hcr : 0 < โ€–cโ€– / r := div_pos (zero_lt_one.trans hc) hr refine' ContinuousLinearMap.op_norm_le_of_shell hr hcr.le hc fun x hโ‚ hโ‚‚ => _ calc โ€–x' xโ€– โ‰ค 1 := hx' _ hโ‚‚ _ โ‰ค โ€–cโ€– / r * โ€–xโ€– := (inv_pos_le_iff_one_le_mul' hcr).1 (by rwa [inv_div]) #align normed_space.polar_ball_subset_closed_ball_div NormedSpace.polar_ball_subset_closedBall_div variable (๐•œ) theorem closedBall_inv_subset_polar_closedBall {r : โ„} : closedBall (0 : Dual ๐•œ E) rโปยน โІ polar ๐•œ (closedBall (0 : E) r) := fun x' hx' x hx => calc โ€–x' xโ€– โ‰ค โ€–x'โ€– * โ€–xโ€– := x'.le_op_norm x _ โ‰ค rโปยน * r := (mul_le_mul (mem_closedBall_zero_iff.1 hx') (mem_closedBall_zero_iff.1 hx) (norm_nonneg _) (dist_nonneg.trans hx')) _ = r / r := (inv_mul_eq_div _ _) _ โ‰ค 1 := div_self_le_one r #align normed_space.closed_ball_inv_subset_polar_closed_ball NormedSpace.closedBall_inv_subset_polar_closedBall /-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน := by refine' Subset.antisymm _ (closedBall_inv_subset_polar_closedBall ๐•œ) intro x' h simp only [mem_closedBall_zero_iff]
refine' ContinuousLinearMap.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) fun z _ => _
/-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน := by refine' Subset.antisymm _ (closedBall_inv_subset_polar_closedBall ๐•œ) intro x' h simp only [mem_closedBall_zero_iff]
Mathlib.Analysis.NormedSpace.Dual.243_0.WirVfj6f5oiZZ2w
/-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน
Mathlib_Analysis_NormedSpace_Dual
๐•œโœ : Type u_1 instโœโต : NontriviallyNormedField ๐•œโœ Eโœ : Type u_2 instโœโด : SeminormedAddCommGroup Eโœ instโœยณ : NormedSpace ๐•œโœ Eโœ ๐•œ : Type u_3 E : Type u_4 instโœยฒ : IsROrC ๐•œ instโœยน : NormedAddCommGroup E instโœ : NormedSpace ๐•œ E r : โ„ hr : 0 < r x' : Dual ๐•œ E h : x' โˆˆ polar ๐•œ (closedBall 0 r) z : E xโœ : z โˆˆ ball 0 r โŠข โ€–x' zโ€– โ‰ค rโปยน * โ€–zโ€–
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.IsROrC import Mathlib.Analysis.LocallyConvex.Polar #align_import analysis.normed_space.dual from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The topological dual of a normed space In this file we define the topological dual `NormedSpace.Dual` of a normed space, and the continuous linear map `NormedSpace.inclusionInDoubleDual` from a normed space into its double dual. For base field `๐•œ = โ„` or `๐•œ = โ„‚`, this map is actually an isometric embedding; we provide a version `NormedSpace.inclusionInDoubleDualLi` of the map which is of type a bundled linear isometric embedding, `E โ†’โ‚—แตข[๐•œ] (Dual ๐•œ (Dual ๐•œ E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `SeminormedAddCommGroup` and we specialize to `NormedAddCommGroup` when needed. ## Main definitions * `inclusionInDoubleDual` and `inclusionInDoubleDualLi` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals `x'` for which `โ€–x' zโ€– โ‰ค 1` for every `z โˆˆ s`. ## Tags dual -/ noncomputable section open Classical Topology Bornology universe u v namespace NormedSpace section General variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable (E : Type*) [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace ๐•œ F] /-- The topological dual of a seminormed space `E`. -/ abbrev Dual : Type _ := E โ†’L[๐•œ] ๐•œ #align normed_space.dual NormedSpace.Dual -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_eq until -- leanprover/lean4#2522 is resolved; remove once fixed instance : NormedSpace ๐•œ (Dual ๐•œ E) := inferInstance -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_le until -- leanprover/lean4#2522 is resolved; remove once fixed instance : SeminormedAddCommGroup (Dual ๐•œ E) := inferInstance /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusionInDoubleDual : E โ†’L[๐•œ] Dual ๐•œ (Dual ๐•œ E) := ContinuousLinearMap.apply ๐•œ ๐•œ #align normed_space.inclusion_in_double_dual NormedSpace.inclusionInDoubleDual @[simp] theorem dual_def (x : E) (f : Dual ๐•œ E) : inclusionInDoubleDual ๐•œ E x f = f x := rfl #align normed_space.dual_def NormedSpace.dual_def theorem inclusionInDoubleDual_norm_eq : โ€–inclusionInDoubleDual ๐•œ Eโ€– = โ€–ContinuousLinearMap.id ๐•œ (Dual ๐•œ E)โ€– := ContinuousLinearMap.op_norm_flip _ #align normed_space.inclusion_in_double_dual_norm_eq NormedSpace.inclusionInDoubleDual_norm_eq theorem inclusionInDoubleDual_norm_le : โ€–inclusionInDoubleDual ๐•œ Eโ€– โ‰ค 1 := by rw [inclusionInDoubleDual_norm_eq] exact ContinuousLinearMap.norm_id_le #align normed_space.inclusion_in_double_dual_norm_le NormedSpace.inclusionInDoubleDual_norm_le theorem double_dual_bound (x : E) : โ€–(inclusionInDoubleDual ๐•œ E) xโ€– โ‰ค โ€–xโ€– := by simpa using ContinuousLinearMap.le_of_op_norm_le _ (inclusionInDoubleDual_norm_le ๐•œ E) x #align normed_space.double_dual_bound NormedSpace.double_dual_bound /-- The dual pairing as a bilinear form. -/ def dualPairing : Dual ๐•œ E โ†’โ‚—[๐•œ] E โ†’โ‚—[๐•œ] ๐•œ := ContinuousLinearMap.coeLM ๐•œ #align normed_space.dual_pairing NormedSpace.dualPairing @[simp] theorem dualPairing_apply {v : Dual ๐•œ E} {x : E} : dualPairing ๐•œ E v x = v x := rfl #align normed_space.dual_pairing_apply NormedSpace.dualPairing_apply theorem dualPairing_separatingLeft : (dualPairing ๐•œ E).SeparatingLeft := by rw [LinearMap.separatingLeft_iff_ker_eq_bot, LinearMap.ker_eq_bot] exact ContinuousLinearMap.coe_injective #align normed_space.dual_pairing_separating_left NormedSpace.dualPairing_separatingLeft end General section BidualIsometry variable (๐•œ : Type v) [IsROrC ๐•œ] {E : Type u} [NormedAddCommGroup E] [NormedSpace ๐•œ E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `ContinuousLinearMap.op_norm_le_bound`. -/ theorem norm_le_dual_bound (x : E) {M : โ„} (hMp : 0 โ‰ค M) (hM : โˆ€ f : Dual ๐•œ E, โ€–f xโ€– โ‰ค M * โ€–fโ€–) : โ€–xโ€– โ‰ค M := by classical by_cases h : x = 0 ยท simp only [h, hMp, norm_zero] ยท obtain โŸจf, hfโ‚, hfxโŸฉ : โˆƒ f : E โ†’L[๐•œ] ๐•œ, โ€–fโ€– = 1 โˆง f x = โ€–xโ€– := exists_dual_vector ๐•œ x h calc โ€–xโ€– = โ€–(โ€–xโ€– : ๐•œ)โ€– := IsROrC.norm_coe_norm.symm _ = โ€–f xโ€– := by rw [hfx] _ โ‰ค M * โ€–fโ€– := (hM f) _ = M := by rw [hfโ‚, mul_one] #align normed_space.norm_le_dual_bound NormedSpace.norm_le_dual_bound theorem eq_zero_of_forall_dual_eq_zero {x : E} (h : โˆ€ f : Dual ๐•œ E, f x = (0 : ๐•œ)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound ๐•œ x le_rfl fun f => by simp [h f]) #align normed_space.eq_zero_of_forall_dual_eq_zero NormedSpace.eq_zero_of_forall_dual_eq_zero theorem eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 โ†” โˆ€ g : Dual ๐•œ E, g x = 0 := โŸจfun hx => by simp [hx], fun h => eq_zero_of_forall_dual_eq_zero ๐•œ hโŸฉ #align normed_space.eq_zero_iff_forall_dual_eq_zero NormedSpace.eq_zero_iff_forall_dual_eq_zero /-- See also `geometric_hahn_banach_point_point`. -/ theorem eq_iff_forall_dual_eq {x y : E} : x = y โ†” โˆ€ g : Dual ๐•œ E, g x = g y := by rw [โ† sub_eq_zero, eq_zero_iff_forall_dual_eq_zero ๐•œ (x - y)] simp [sub_eq_zero] #align normed_space.eq_iff_forall_dual_eq NormedSpace.eq_iff_forall_dual_eq /-- The inclusion of a normed space in its double dual is an isometry onto its image.-/ def inclusionInDoubleDualLi : E โ†’โ‚—แตข[๐•œ] Dual ๐•œ (Dual ๐•œ E) := { inclusionInDoubleDual ๐•œ E with norm_map' := by intro x apply le_antisymm ยท exact double_dual_bound ๐•œ E x rw [ContinuousLinearMap.norm_def] refine' le_csInf ContinuousLinearMap.bounds_nonempty _ rintro c โŸจhc1, hc2โŸฉ exact norm_le_dual_bound ๐•œ x hc1 hc2 } #align normed_space.inclusion_in_double_dual_li NormedSpace.inclusionInDoubleDualLi end BidualIsometry section PolarSets open Metric Set NormedSpace /-- Given a subset `s` in a normed space `E` (over a field `๐•œ`), the polar `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals which evaluate to something of norm at most one at all points `z โˆˆ s`. -/ def polar (๐•œ : Type*) [NontriviallyNormedField ๐•œ] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] : Set E โ†’ Set (Dual ๐•œ E) := (dualPairing ๐•œ E).flip.polar #align normed_space.polar NormedSpace.polar variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] theorem mem_polar_iff {x' : Dual ๐•œ E} (s : Set E) : x' โˆˆ polar ๐•œ s โ†” โˆ€ z โˆˆ s, โ€–x' zโ€– โ‰ค 1 := Iff.rfl #align normed_space.mem_polar_iff NormedSpace.mem_polar_iff @[simp] theorem polar_univ : polar ๐•œ (univ : Set E) = {(0 : Dual ๐•œ E)} := (dualPairing ๐•œ E).flip.polar_univ (LinearMap.flip_separatingRight.mpr (dualPairing_separatingLeft ๐•œ E)) #align normed_space.polar_univ NormedSpace.polar_univ theorem isClosed_polar (s : Set E) : IsClosed (polar ๐•œ s) := by dsimp only [NormedSpace.polar] simp only [LinearMap.polar_eq_iInter, LinearMap.flip_apply] refine' isClosed_biInter fun z _ => _ exact isClosed_Iic.preimage (ContinuousLinearMap.apply ๐•œ ๐•œ z).continuous.norm #align normed_space.is_closed_polar NormedSpace.isClosed_polar @[simp] theorem polar_closure (s : Set E) : polar ๐•œ (closure s) = polar ๐•œ s := ((dualPairing ๐•œ E).flip.polar_antitone subset_closure).antisymm <| (dualPairing ๐•œ E).flip.polar_gc.l_le <| closure_minimal ((dualPairing ๐•œ E).flip.polar_gc.le_u_l s) <| by simpa [LinearMap.flip_flip] using (isClosed_polar _ _).preimage (inclusionInDoubleDual ๐•œ E).continuous #align normed_space.polar_closure NormedSpace.polar_closure variable {๐•œ} /-- If `x'` is a dual element such that the norms `โ€–x' zโ€–` are bounded for `z โˆˆ s`, then a small scalar multiple of `x'` is in `polar ๐•œ s`. -/ theorem smul_mem_polar {s : Set E} {x' : Dual ๐•œ E} {c : ๐•œ} (hc : โˆ€ z, z โˆˆ s โ†’ โ€–x' zโ€– โ‰ค โ€–cโ€–) : cโปยน โ€ข x' โˆˆ polar ๐•œ s := by by_cases c_zero : c = 0 ยท simp only [c_zero, inv_zero, zero_smul] exact (dualPairing ๐•œ E).flip.zero_mem_polar _ have eq : โˆ€ z, โ€–cโปยน โ€ข x' zโ€– = โ€–cโปยนโ€– * โ€–x' zโ€– := fun z => norm_smul cโปยน _ have le : โˆ€ z, z โˆˆ s โ†’ โ€–cโปยน โ€ข x' zโ€– โ‰ค โ€–cโปยนโ€– * โ€–cโ€– := by intro z hzs rw [eq z] apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _) have cancel : โ€–cโปยนโ€– * โ€–cโ€– = 1 := by simp only [c_zero, norm_eq_zero, Ne.def, not_false_iff, inv_mul_cancel, norm_inv] rwa [cancel] at le #align normed_space.smul_mem_polar NormedSpace.smul_mem_polar theorem polar_ball_subset_closedBall_div {c : ๐•œ} (hc : 1 < โ€–cโ€–) {r : โ„} (hr : 0 < r) : polar ๐•œ (ball (0 : E) r) โІ closedBall (0 : Dual ๐•œ E) (โ€–cโ€– / r) := by intro x' hx' rw [mem_polar_iff] at hx' simp only [polar, mem_setOf, mem_closedBall_zero_iff, mem_ball_zero_iff] at * have hcr : 0 < โ€–cโ€– / r := div_pos (zero_lt_one.trans hc) hr refine' ContinuousLinearMap.op_norm_le_of_shell hr hcr.le hc fun x hโ‚ hโ‚‚ => _ calc โ€–x' xโ€– โ‰ค 1 := hx' _ hโ‚‚ _ โ‰ค โ€–cโ€– / r * โ€–xโ€– := (inv_pos_le_iff_one_le_mul' hcr).1 (by rwa [inv_div]) #align normed_space.polar_ball_subset_closed_ball_div NormedSpace.polar_ball_subset_closedBall_div variable (๐•œ) theorem closedBall_inv_subset_polar_closedBall {r : โ„} : closedBall (0 : Dual ๐•œ E) rโปยน โІ polar ๐•œ (closedBall (0 : E) r) := fun x' hx' x hx => calc โ€–x' xโ€– โ‰ค โ€–x'โ€– * โ€–xโ€– := x'.le_op_norm x _ โ‰ค rโปยน * r := (mul_le_mul (mem_closedBall_zero_iff.1 hx') (mem_closedBall_zero_iff.1 hx) (norm_nonneg _) (dist_nonneg.trans hx')) _ = r / r := (inv_mul_eq_div _ _) _ โ‰ค 1 := div_self_le_one r #align normed_space.closed_ball_inv_subset_polar_closed_ball NormedSpace.closedBall_inv_subset_polar_closedBall /-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน := by refine' Subset.antisymm _ (closedBall_inv_subset_polar_closedBall ๐•œ) intro x' h simp only [mem_closedBall_zero_iff] refine' ContinuousLinearMap.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) fun z _ => _
simpa only [one_div] using LinearMap.bound_of_ball_bound' hr 1 x'.toLinearMap h z
/-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน := by refine' Subset.antisymm _ (closedBall_inv_subset_polar_closedBall ๐•œ) intro x' h simp only [mem_closedBall_zero_iff] refine' ContinuousLinearMap.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) fun z _ => _
Mathlib.Analysis.NormedSpace.Dual.243_0.WirVfj6f5oiZZ2w
/-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน
Mathlib_Analysis_NormedSpace_Dual
๐•œ : Type u_1 instโœยฒ : NontriviallyNormedField ๐•œ E : Type u_2 instโœยน : SeminormedAddCommGroup E instโœ : NormedSpace ๐•œ E s : Set E s_nhd : s โˆˆ ๐“ 0 โŠข IsBounded (polar ๐•œ s)
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.IsROrC import Mathlib.Analysis.LocallyConvex.Polar #align_import analysis.normed_space.dual from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The topological dual of a normed space In this file we define the topological dual `NormedSpace.Dual` of a normed space, and the continuous linear map `NormedSpace.inclusionInDoubleDual` from a normed space into its double dual. For base field `๐•œ = โ„` or `๐•œ = โ„‚`, this map is actually an isometric embedding; we provide a version `NormedSpace.inclusionInDoubleDualLi` of the map which is of type a bundled linear isometric embedding, `E โ†’โ‚—แตข[๐•œ] (Dual ๐•œ (Dual ๐•œ E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `SeminormedAddCommGroup` and we specialize to `NormedAddCommGroup` when needed. ## Main definitions * `inclusionInDoubleDual` and `inclusionInDoubleDualLi` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals `x'` for which `โ€–x' zโ€– โ‰ค 1` for every `z โˆˆ s`. ## Tags dual -/ noncomputable section open Classical Topology Bornology universe u v namespace NormedSpace section General variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable (E : Type*) [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace ๐•œ F] /-- The topological dual of a seminormed space `E`. -/ abbrev Dual : Type _ := E โ†’L[๐•œ] ๐•œ #align normed_space.dual NormedSpace.Dual -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_eq until -- leanprover/lean4#2522 is resolved; remove once fixed instance : NormedSpace ๐•œ (Dual ๐•œ E) := inferInstance -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_le until -- leanprover/lean4#2522 is resolved; remove once fixed instance : SeminormedAddCommGroup (Dual ๐•œ E) := inferInstance /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusionInDoubleDual : E โ†’L[๐•œ] Dual ๐•œ (Dual ๐•œ E) := ContinuousLinearMap.apply ๐•œ ๐•œ #align normed_space.inclusion_in_double_dual NormedSpace.inclusionInDoubleDual @[simp] theorem dual_def (x : E) (f : Dual ๐•œ E) : inclusionInDoubleDual ๐•œ E x f = f x := rfl #align normed_space.dual_def NormedSpace.dual_def theorem inclusionInDoubleDual_norm_eq : โ€–inclusionInDoubleDual ๐•œ Eโ€– = โ€–ContinuousLinearMap.id ๐•œ (Dual ๐•œ E)โ€– := ContinuousLinearMap.op_norm_flip _ #align normed_space.inclusion_in_double_dual_norm_eq NormedSpace.inclusionInDoubleDual_norm_eq theorem inclusionInDoubleDual_norm_le : โ€–inclusionInDoubleDual ๐•œ Eโ€– โ‰ค 1 := by rw [inclusionInDoubleDual_norm_eq] exact ContinuousLinearMap.norm_id_le #align normed_space.inclusion_in_double_dual_norm_le NormedSpace.inclusionInDoubleDual_norm_le theorem double_dual_bound (x : E) : โ€–(inclusionInDoubleDual ๐•œ E) xโ€– โ‰ค โ€–xโ€– := by simpa using ContinuousLinearMap.le_of_op_norm_le _ (inclusionInDoubleDual_norm_le ๐•œ E) x #align normed_space.double_dual_bound NormedSpace.double_dual_bound /-- The dual pairing as a bilinear form. -/ def dualPairing : Dual ๐•œ E โ†’โ‚—[๐•œ] E โ†’โ‚—[๐•œ] ๐•œ := ContinuousLinearMap.coeLM ๐•œ #align normed_space.dual_pairing NormedSpace.dualPairing @[simp] theorem dualPairing_apply {v : Dual ๐•œ E} {x : E} : dualPairing ๐•œ E v x = v x := rfl #align normed_space.dual_pairing_apply NormedSpace.dualPairing_apply theorem dualPairing_separatingLeft : (dualPairing ๐•œ E).SeparatingLeft := by rw [LinearMap.separatingLeft_iff_ker_eq_bot, LinearMap.ker_eq_bot] exact ContinuousLinearMap.coe_injective #align normed_space.dual_pairing_separating_left NormedSpace.dualPairing_separatingLeft end General section BidualIsometry variable (๐•œ : Type v) [IsROrC ๐•œ] {E : Type u} [NormedAddCommGroup E] [NormedSpace ๐•œ E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `ContinuousLinearMap.op_norm_le_bound`. -/ theorem norm_le_dual_bound (x : E) {M : โ„} (hMp : 0 โ‰ค M) (hM : โˆ€ f : Dual ๐•œ E, โ€–f xโ€– โ‰ค M * โ€–fโ€–) : โ€–xโ€– โ‰ค M := by classical by_cases h : x = 0 ยท simp only [h, hMp, norm_zero] ยท obtain โŸจf, hfโ‚, hfxโŸฉ : โˆƒ f : E โ†’L[๐•œ] ๐•œ, โ€–fโ€– = 1 โˆง f x = โ€–xโ€– := exists_dual_vector ๐•œ x h calc โ€–xโ€– = โ€–(โ€–xโ€– : ๐•œ)โ€– := IsROrC.norm_coe_norm.symm _ = โ€–f xโ€– := by rw [hfx] _ โ‰ค M * โ€–fโ€– := (hM f) _ = M := by rw [hfโ‚, mul_one] #align normed_space.norm_le_dual_bound NormedSpace.norm_le_dual_bound theorem eq_zero_of_forall_dual_eq_zero {x : E} (h : โˆ€ f : Dual ๐•œ E, f x = (0 : ๐•œ)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound ๐•œ x le_rfl fun f => by simp [h f]) #align normed_space.eq_zero_of_forall_dual_eq_zero NormedSpace.eq_zero_of_forall_dual_eq_zero theorem eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 โ†” โˆ€ g : Dual ๐•œ E, g x = 0 := โŸจfun hx => by simp [hx], fun h => eq_zero_of_forall_dual_eq_zero ๐•œ hโŸฉ #align normed_space.eq_zero_iff_forall_dual_eq_zero NormedSpace.eq_zero_iff_forall_dual_eq_zero /-- See also `geometric_hahn_banach_point_point`. -/ theorem eq_iff_forall_dual_eq {x y : E} : x = y โ†” โˆ€ g : Dual ๐•œ E, g x = g y := by rw [โ† sub_eq_zero, eq_zero_iff_forall_dual_eq_zero ๐•œ (x - y)] simp [sub_eq_zero] #align normed_space.eq_iff_forall_dual_eq NormedSpace.eq_iff_forall_dual_eq /-- The inclusion of a normed space in its double dual is an isometry onto its image.-/ def inclusionInDoubleDualLi : E โ†’โ‚—แตข[๐•œ] Dual ๐•œ (Dual ๐•œ E) := { inclusionInDoubleDual ๐•œ E with norm_map' := by intro x apply le_antisymm ยท exact double_dual_bound ๐•œ E x rw [ContinuousLinearMap.norm_def] refine' le_csInf ContinuousLinearMap.bounds_nonempty _ rintro c โŸจhc1, hc2โŸฉ exact norm_le_dual_bound ๐•œ x hc1 hc2 } #align normed_space.inclusion_in_double_dual_li NormedSpace.inclusionInDoubleDualLi end BidualIsometry section PolarSets open Metric Set NormedSpace /-- Given a subset `s` in a normed space `E` (over a field `๐•œ`), the polar `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals which evaluate to something of norm at most one at all points `z โˆˆ s`. -/ def polar (๐•œ : Type*) [NontriviallyNormedField ๐•œ] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] : Set E โ†’ Set (Dual ๐•œ E) := (dualPairing ๐•œ E).flip.polar #align normed_space.polar NormedSpace.polar variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] theorem mem_polar_iff {x' : Dual ๐•œ E} (s : Set E) : x' โˆˆ polar ๐•œ s โ†” โˆ€ z โˆˆ s, โ€–x' zโ€– โ‰ค 1 := Iff.rfl #align normed_space.mem_polar_iff NormedSpace.mem_polar_iff @[simp] theorem polar_univ : polar ๐•œ (univ : Set E) = {(0 : Dual ๐•œ E)} := (dualPairing ๐•œ E).flip.polar_univ (LinearMap.flip_separatingRight.mpr (dualPairing_separatingLeft ๐•œ E)) #align normed_space.polar_univ NormedSpace.polar_univ theorem isClosed_polar (s : Set E) : IsClosed (polar ๐•œ s) := by dsimp only [NormedSpace.polar] simp only [LinearMap.polar_eq_iInter, LinearMap.flip_apply] refine' isClosed_biInter fun z _ => _ exact isClosed_Iic.preimage (ContinuousLinearMap.apply ๐•œ ๐•œ z).continuous.norm #align normed_space.is_closed_polar NormedSpace.isClosed_polar @[simp] theorem polar_closure (s : Set E) : polar ๐•œ (closure s) = polar ๐•œ s := ((dualPairing ๐•œ E).flip.polar_antitone subset_closure).antisymm <| (dualPairing ๐•œ E).flip.polar_gc.l_le <| closure_minimal ((dualPairing ๐•œ E).flip.polar_gc.le_u_l s) <| by simpa [LinearMap.flip_flip] using (isClosed_polar _ _).preimage (inclusionInDoubleDual ๐•œ E).continuous #align normed_space.polar_closure NormedSpace.polar_closure variable {๐•œ} /-- If `x'` is a dual element such that the norms `โ€–x' zโ€–` are bounded for `z โˆˆ s`, then a small scalar multiple of `x'` is in `polar ๐•œ s`. -/ theorem smul_mem_polar {s : Set E} {x' : Dual ๐•œ E} {c : ๐•œ} (hc : โˆ€ z, z โˆˆ s โ†’ โ€–x' zโ€– โ‰ค โ€–cโ€–) : cโปยน โ€ข x' โˆˆ polar ๐•œ s := by by_cases c_zero : c = 0 ยท simp only [c_zero, inv_zero, zero_smul] exact (dualPairing ๐•œ E).flip.zero_mem_polar _ have eq : โˆ€ z, โ€–cโปยน โ€ข x' zโ€– = โ€–cโปยนโ€– * โ€–x' zโ€– := fun z => norm_smul cโปยน _ have le : โˆ€ z, z โˆˆ s โ†’ โ€–cโปยน โ€ข x' zโ€– โ‰ค โ€–cโปยนโ€– * โ€–cโ€– := by intro z hzs rw [eq z] apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _) have cancel : โ€–cโปยนโ€– * โ€–cโ€– = 1 := by simp only [c_zero, norm_eq_zero, Ne.def, not_false_iff, inv_mul_cancel, norm_inv] rwa [cancel] at le #align normed_space.smul_mem_polar NormedSpace.smul_mem_polar theorem polar_ball_subset_closedBall_div {c : ๐•œ} (hc : 1 < โ€–cโ€–) {r : โ„} (hr : 0 < r) : polar ๐•œ (ball (0 : E) r) โІ closedBall (0 : Dual ๐•œ E) (โ€–cโ€– / r) := by intro x' hx' rw [mem_polar_iff] at hx' simp only [polar, mem_setOf, mem_closedBall_zero_iff, mem_ball_zero_iff] at * have hcr : 0 < โ€–cโ€– / r := div_pos (zero_lt_one.trans hc) hr refine' ContinuousLinearMap.op_norm_le_of_shell hr hcr.le hc fun x hโ‚ hโ‚‚ => _ calc โ€–x' xโ€– โ‰ค 1 := hx' _ hโ‚‚ _ โ‰ค โ€–cโ€– / r * โ€–xโ€– := (inv_pos_le_iff_one_le_mul' hcr).1 (by rwa [inv_div]) #align normed_space.polar_ball_subset_closed_ball_div NormedSpace.polar_ball_subset_closedBall_div variable (๐•œ) theorem closedBall_inv_subset_polar_closedBall {r : โ„} : closedBall (0 : Dual ๐•œ E) rโปยน โІ polar ๐•œ (closedBall (0 : E) r) := fun x' hx' x hx => calc โ€–x' xโ€– โ‰ค โ€–x'โ€– * โ€–xโ€– := x'.le_op_norm x _ โ‰ค rโปยน * r := (mul_le_mul (mem_closedBall_zero_iff.1 hx') (mem_closedBall_zero_iff.1 hx) (norm_nonneg _) (dist_nonneg.trans hx')) _ = r / r := (inv_mul_eq_div _ _) _ โ‰ค 1 := div_self_le_one r #align normed_space.closed_ball_inv_subset_polar_closed_ball NormedSpace.closedBall_inv_subset_polar_closedBall /-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน := by refine' Subset.antisymm _ (closedBall_inv_subset_polar_closedBall ๐•œ) intro x' h simp only [mem_closedBall_zero_iff] refine' ContinuousLinearMap.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) fun z _ => _ simpa only [one_div] using LinearMap.bound_of_ball_bound' hr 1 x'.toLinearMap h z #align normed_space.polar_closed_ball NormedSpace.polar_closedBall /-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s) := by
obtain โŸจa, haโŸฉ : โˆƒ a : ๐•œ, 1 < โ€–aโ€– := NormedField.exists_one_lt_norm ๐•œ
/-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s) := by
Mathlib.Analysis.NormedSpace.Dual.254_0.WirVfj6f5oiZZ2w
/-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s)
Mathlib_Analysis_NormedSpace_Dual
case intro ๐•œ : Type u_1 instโœยฒ : NontriviallyNormedField ๐•œ E : Type u_2 instโœยน : SeminormedAddCommGroup E instโœ : NormedSpace ๐•œ E s : Set E s_nhd : s โˆˆ ๐“ 0 a : ๐•œ ha : 1 < โ€–aโ€– โŠข IsBounded (polar ๐•œ s)
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.IsROrC import Mathlib.Analysis.LocallyConvex.Polar #align_import analysis.normed_space.dual from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The topological dual of a normed space In this file we define the topological dual `NormedSpace.Dual` of a normed space, and the continuous linear map `NormedSpace.inclusionInDoubleDual` from a normed space into its double dual. For base field `๐•œ = โ„` or `๐•œ = โ„‚`, this map is actually an isometric embedding; we provide a version `NormedSpace.inclusionInDoubleDualLi` of the map which is of type a bundled linear isometric embedding, `E โ†’โ‚—แตข[๐•œ] (Dual ๐•œ (Dual ๐•œ E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `SeminormedAddCommGroup` and we specialize to `NormedAddCommGroup` when needed. ## Main definitions * `inclusionInDoubleDual` and `inclusionInDoubleDualLi` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals `x'` for which `โ€–x' zโ€– โ‰ค 1` for every `z โˆˆ s`. ## Tags dual -/ noncomputable section open Classical Topology Bornology universe u v namespace NormedSpace section General variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable (E : Type*) [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace ๐•œ F] /-- The topological dual of a seminormed space `E`. -/ abbrev Dual : Type _ := E โ†’L[๐•œ] ๐•œ #align normed_space.dual NormedSpace.Dual -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_eq until -- leanprover/lean4#2522 is resolved; remove once fixed instance : NormedSpace ๐•œ (Dual ๐•œ E) := inferInstance -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_le until -- leanprover/lean4#2522 is resolved; remove once fixed instance : SeminormedAddCommGroup (Dual ๐•œ E) := inferInstance /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusionInDoubleDual : E โ†’L[๐•œ] Dual ๐•œ (Dual ๐•œ E) := ContinuousLinearMap.apply ๐•œ ๐•œ #align normed_space.inclusion_in_double_dual NormedSpace.inclusionInDoubleDual @[simp] theorem dual_def (x : E) (f : Dual ๐•œ E) : inclusionInDoubleDual ๐•œ E x f = f x := rfl #align normed_space.dual_def NormedSpace.dual_def theorem inclusionInDoubleDual_norm_eq : โ€–inclusionInDoubleDual ๐•œ Eโ€– = โ€–ContinuousLinearMap.id ๐•œ (Dual ๐•œ E)โ€– := ContinuousLinearMap.op_norm_flip _ #align normed_space.inclusion_in_double_dual_norm_eq NormedSpace.inclusionInDoubleDual_norm_eq theorem inclusionInDoubleDual_norm_le : โ€–inclusionInDoubleDual ๐•œ Eโ€– โ‰ค 1 := by rw [inclusionInDoubleDual_norm_eq] exact ContinuousLinearMap.norm_id_le #align normed_space.inclusion_in_double_dual_norm_le NormedSpace.inclusionInDoubleDual_norm_le theorem double_dual_bound (x : E) : โ€–(inclusionInDoubleDual ๐•œ E) xโ€– โ‰ค โ€–xโ€– := by simpa using ContinuousLinearMap.le_of_op_norm_le _ (inclusionInDoubleDual_norm_le ๐•œ E) x #align normed_space.double_dual_bound NormedSpace.double_dual_bound /-- The dual pairing as a bilinear form. -/ def dualPairing : Dual ๐•œ E โ†’โ‚—[๐•œ] E โ†’โ‚—[๐•œ] ๐•œ := ContinuousLinearMap.coeLM ๐•œ #align normed_space.dual_pairing NormedSpace.dualPairing @[simp] theorem dualPairing_apply {v : Dual ๐•œ E} {x : E} : dualPairing ๐•œ E v x = v x := rfl #align normed_space.dual_pairing_apply NormedSpace.dualPairing_apply theorem dualPairing_separatingLeft : (dualPairing ๐•œ E).SeparatingLeft := by rw [LinearMap.separatingLeft_iff_ker_eq_bot, LinearMap.ker_eq_bot] exact ContinuousLinearMap.coe_injective #align normed_space.dual_pairing_separating_left NormedSpace.dualPairing_separatingLeft end General section BidualIsometry variable (๐•œ : Type v) [IsROrC ๐•œ] {E : Type u} [NormedAddCommGroup E] [NormedSpace ๐•œ E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `ContinuousLinearMap.op_norm_le_bound`. -/ theorem norm_le_dual_bound (x : E) {M : โ„} (hMp : 0 โ‰ค M) (hM : โˆ€ f : Dual ๐•œ E, โ€–f xโ€– โ‰ค M * โ€–fโ€–) : โ€–xโ€– โ‰ค M := by classical by_cases h : x = 0 ยท simp only [h, hMp, norm_zero] ยท obtain โŸจf, hfโ‚, hfxโŸฉ : โˆƒ f : E โ†’L[๐•œ] ๐•œ, โ€–fโ€– = 1 โˆง f x = โ€–xโ€– := exists_dual_vector ๐•œ x h calc โ€–xโ€– = โ€–(โ€–xโ€– : ๐•œ)โ€– := IsROrC.norm_coe_norm.symm _ = โ€–f xโ€– := by rw [hfx] _ โ‰ค M * โ€–fโ€– := (hM f) _ = M := by rw [hfโ‚, mul_one] #align normed_space.norm_le_dual_bound NormedSpace.norm_le_dual_bound theorem eq_zero_of_forall_dual_eq_zero {x : E} (h : โˆ€ f : Dual ๐•œ E, f x = (0 : ๐•œ)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound ๐•œ x le_rfl fun f => by simp [h f]) #align normed_space.eq_zero_of_forall_dual_eq_zero NormedSpace.eq_zero_of_forall_dual_eq_zero theorem eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 โ†” โˆ€ g : Dual ๐•œ E, g x = 0 := โŸจfun hx => by simp [hx], fun h => eq_zero_of_forall_dual_eq_zero ๐•œ hโŸฉ #align normed_space.eq_zero_iff_forall_dual_eq_zero NormedSpace.eq_zero_iff_forall_dual_eq_zero /-- See also `geometric_hahn_banach_point_point`. -/ theorem eq_iff_forall_dual_eq {x y : E} : x = y โ†” โˆ€ g : Dual ๐•œ E, g x = g y := by rw [โ† sub_eq_zero, eq_zero_iff_forall_dual_eq_zero ๐•œ (x - y)] simp [sub_eq_zero] #align normed_space.eq_iff_forall_dual_eq NormedSpace.eq_iff_forall_dual_eq /-- The inclusion of a normed space in its double dual is an isometry onto its image.-/ def inclusionInDoubleDualLi : E โ†’โ‚—แตข[๐•œ] Dual ๐•œ (Dual ๐•œ E) := { inclusionInDoubleDual ๐•œ E with norm_map' := by intro x apply le_antisymm ยท exact double_dual_bound ๐•œ E x rw [ContinuousLinearMap.norm_def] refine' le_csInf ContinuousLinearMap.bounds_nonempty _ rintro c โŸจhc1, hc2โŸฉ exact norm_le_dual_bound ๐•œ x hc1 hc2 } #align normed_space.inclusion_in_double_dual_li NormedSpace.inclusionInDoubleDualLi end BidualIsometry section PolarSets open Metric Set NormedSpace /-- Given a subset `s` in a normed space `E` (over a field `๐•œ`), the polar `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals which evaluate to something of norm at most one at all points `z โˆˆ s`. -/ def polar (๐•œ : Type*) [NontriviallyNormedField ๐•œ] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] : Set E โ†’ Set (Dual ๐•œ E) := (dualPairing ๐•œ E).flip.polar #align normed_space.polar NormedSpace.polar variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] theorem mem_polar_iff {x' : Dual ๐•œ E} (s : Set E) : x' โˆˆ polar ๐•œ s โ†” โˆ€ z โˆˆ s, โ€–x' zโ€– โ‰ค 1 := Iff.rfl #align normed_space.mem_polar_iff NormedSpace.mem_polar_iff @[simp] theorem polar_univ : polar ๐•œ (univ : Set E) = {(0 : Dual ๐•œ E)} := (dualPairing ๐•œ E).flip.polar_univ (LinearMap.flip_separatingRight.mpr (dualPairing_separatingLeft ๐•œ E)) #align normed_space.polar_univ NormedSpace.polar_univ theorem isClosed_polar (s : Set E) : IsClosed (polar ๐•œ s) := by dsimp only [NormedSpace.polar] simp only [LinearMap.polar_eq_iInter, LinearMap.flip_apply] refine' isClosed_biInter fun z _ => _ exact isClosed_Iic.preimage (ContinuousLinearMap.apply ๐•œ ๐•œ z).continuous.norm #align normed_space.is_closed_polar NormedSpace.isClosed_polar @[simp] theorem polar_closure (s : Set E) : polar ๐•œ (closure s) = polar ๐•œ s := ((dualPairing ๐•œ E).flip.polar_antitone subset_closure).antisymm <| (dualPairing ๐•œ E).flip.polar_gc.l_le <| closure_minimal ((dualPairing ๐•œ E).flip.polar_gc.le_u_l s) <| by simpa [LinearMap.flip_flip] using (isClosed_polar _ _).preimage (inclusionInDoubleDual ๐•œ E).continuous #align normed_space.polar_closure NormedSpace.polar_closure variable {๐•œ} /-- If `x'` is a dual element such that the norms `โ€–x' zโ€–` are bounded for `z โˆˆ s`, then a small scalar multiple of `x'` is in `polar ๐•œ s`. -/ theorem smul_mem_polar {s : Set E} {x' : Dual ๐•œ E} {c : ๐•œ} (hc : โˆ€ z, z โˆˆ s โ†’ โ€–x' zโ€– โ‰ค โ€–cโ€–) : cโปยน โ€ข x' โˆˆ polar ๐•œ s := by by_cases c_zero : c = 0 ยท simp only [c_zero, inv_zero, zero_smul] exact (dualPairing ๐•œ E).flip.zero_mem_polar _ have eq : โˆ€ z, โ€–cโปยน โ€ข x' zโ€– = โ€–cโปยนโ€– * โ€–x' zโ€– := fun z => norm_smul cโปยน _ have le : โˆ€ z, z โˆˆ s โ†’ โ€–cโปยน โ€ข x' zโ€– โ‰ค โ€–cโปยนโ€– * โ€–cโ€– := by intro z hzs rw [eq z] apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _) have cancel : โ€–cโปยนโ€– * โ€–cโ€– = 1 := by simp only [c_zero, norm_eq_zero, Ne.def, not_false_iff, inv_mul_cancel, norm_inv] rwa [cancel] at le #align normed_space.smul_mem_polar NormedSpace.smul_mem_polar theorem polar_ball_subset_closedBall_div {c : ๐•œ} (hc : 1 < โ€–cโ€–) {r : โ„} (hr : 0 < r) : polar ๐•œ (ball (0 : E) r) โІ closedBall (0 : Dual ๐•œ E) (โ€–cโ€– / r) := by intro x' hx' rw [mem_polar_iff] at hx' simp only [polar, mem_setOf, mem_closedBall_zero_iff, mem_ball_zero_iff] at * have hcr : 0 < โ€–cโ€– / r := div_pos (zero_lt_one.trans hc) hr refine' ContinuousLinearMap.op_norm_le_of_shell hr hcr.le hc fun x hโ‚ hโ‚‚ => _ calc โ€–x' xโ€– โ‰ค 1 := hx' _ hโ‚‚ _ โ‰ค โ€–cโ€– / r * โ€–xโ€– := (inv_pos_le_iff_one_le_mul' hcr).1 (by rwa [inv_div]) #align normed_space.polar_ball_subset_closed_ball_div NormedSpace.polar_ball_subset_closedBall_div variable (๐•œ) theorem closedBall_inv_subset_polar_closedBall {r : โ„} : closedBall (0 : Dual ๐•œ E) rโปยน โІ polar ๐•œ (closedBall (0 : E) r) := fun x' hx' x hx => calc โ€–x' xโ€– โ‰ค โ€–x'โ€– * โ€–xโ€– := x'.le_op_norm x _ โ‰ค rโปยน * r := (mul_le_mul (mem_closedBall_zero_iff.1 hx') (mem_closedBall_zero_iff.1 hx) (norm_nonneg _) (dist_nonneg.trans hx')) _ = r / r := (inv_mul_eq_div _ _) _ โ‰ค 1 := div_self_le_one r #align normed_space.closed_ball_inv_subset_polar_closed_ball NormedSpace.closedBall_inv_subset_polar_closedBall /-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน := by refine' Subset.antisymm _ (closedBall_inv_subset_polar_closedBall ๐•œ) intro x' h simp only [mem_closedBall_zero_iff] refine' ContinuousLinearMap.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) fun z _ => _ simpa only [one_div] using LinearMap.bound_of_ball_bound' hr 1 x'.toLinearMap h z #align normed_space.polar_closed_ball NormedSpace.polar_closedBall /-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s) := by obtain โŸจa, haโŸฉ : โˆƒ a : ๐•œ, 1 < โ€–aโ€– := NormedField.exists_one_lt_norm ๐•œ
obtain โŸจr, r_pos, r_ballโŸฉ : โˆƒ r : โ„, 0 < r โˆง ball 0 r โІ s := Metric.mem_nhds_iff.1 s_nhd
/-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s) := by obtain โŸจa, haโŸฉ : โˆƒ a : ๐•œ, 1 < โ€–aโ€– := NormedField.exists_one_lt_norm ๐•œ
Mathlib.Analysis.NormedSpace.Dual.254_0.WirVfj6f5oiZZ2w
/-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s)
Mathlib_Analysis_NormedSpace_Dual
case intro.intro.intro ๐•œ : Type u_1 instโœยฒ : NontriviallyNormedField ๐•œ E : Type u_2 instโœยน : SeminormedAddCommGroup E instโœ : NormedSpace ๐•œ E s : Set E s_nhd : s โˆˆ ๐“ 0 a : ๐•œ ha : 1 < โ€–aโ€– r : โ„ r_pos : 0 < r r_ball : ball 0 r โІ s โŠข IsBounded (polar ๐•œ s)
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.IsROrC import Mathlib.Analysis.LocallyConvex.Polar #align_import analysis.normed_space.dual from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The topological dual of a normed space In this file we define the topological dual `NormedSpace.Dual` of a normed space, and the continuous linear map `NormedSpace.inclusionInDoubleDual` from a normed space into its double dual. For base field `๐•œ = โ„` or `๐•œ = โ„‚`, this map is actually an isometric embedding; we provide a version `NormedSpace.inclusionInDoubleDualLi` of the map which is of type a bundled linear isometric embedding, `E โ†’โ‚—แตข[๐•œ] (Dual ๐•œ (Dual ๐•œ E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `SeminormedAddCommGroup` and we specialize to `NormedAddCommGroup` when needed. ## Main definitions * `inclusionInDoubleDual` and `inclusionInDoubleDualLi` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals `x'` for which `โ€–x' zโ€– โ‰ค 1` for every `z โˆˆ s`. ## Tags dual -/ noncomputable section open Classical Topology Bornology universe u v namespace NormedSpace section General variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable (E : Type*) [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace ๐•œ F] /-- The topological dual of a seminormed space `E`. -/ abbrev Dual : Type _ := E โ†’L[๐•œ] ๐•œ #align normed_space.dual NormedSpace.Dual -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_eq until -- leanprover/lean4#2522 is resolved; remove once fixed instance : NormedSpace ๐•œ (Dual ๐•œ E) := inferInstance -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_le until -- leanprover/lean4#2522 is resolved; remove once fixed instance : SeminormedAddCommGroup (Dual ๐•œ E) := inferInstance /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusionInDoubleDual : E โ†’L[๐•œ] Dual ๐•œ (Dual ๐•œ E) := ContinuousLinearMap.apply ๐•œ ๐•œ #align normed_space.inclusion_in_double_dual NormedSpace.inclusionInDoubleDual @[simp] theorem dual_def (x : E) (f : Dual ๐•œ E) : inclusionInDoubleDual ๐•œ E x f = f x := rfl #align normed_space.dual_def NormedSpace.dual_def theorem inclusionInDoubleDual_norm_eq : โ€–inclusionInDoubleDual ๐•œ Eโ€– = โ€–ContinuousLinearMap.id ๐•œ (Dual ๐•œ E)โ€– := ContinuousLinearMap.op_norm_flip _ #align normed_space.inclusion_in_double_dual_norm_eq NormedSpace.inclusionInDoubleDual_norm_eq theorem inclusionInDoubleDual_norm_le : โ€–inclusionInDoubleDual ๐•œ Eโ€– โ‰ค 1 := by rw [inclusionInDoubleDual_norm_eq] exact ContinuousLinearMap.norm_id_le #align normed_space.inclusion_in_double_dual_norm_le NormedSpace.inclusionInDoubleDual_norm_le theorem double_dual_bound (x : E) : โ€–(inclusionInDoubleDual ๐•œ E) xโ€– โ‰ค โ€–xโ€– := by simpa using ContinuousLinearMap.le_of_op_norm_le _ (inclusionInDoubleDual_norm_le ๐•œ E) x #align normed_space.double_dual_bound NormedSpace.double_dual_bound /-- The dual pairing as a bilinear form. -/ def dualPairing : Dual ๐•œ E โ†’โ‚—[๐•œ] E โ†’โ‚—[๐•œ] ๐•œ := ContinuousLinearMap.coeLM ๐•œ #align normed_space.dual_pairing NormedSpace.dualPairing @[simp] theorem dualPairing_apply {v : Dual ๐•œ E} {x : E} : dualPairing ๐•œ E v x = v x := rfl #align normed_space.dual_pairing_apply NormedSpace.dualPairing_apply theorem dualPairing_separatingLeft : (dualPairing ๐•œ E).SeparatingLeft := by rw [LinearMap.separatingLeft_iff_ker_eq_bot, LinearMap.ker_eq_bot] exact ContinuousLinearMap.coe_injective #align normed_space.dual_pairing_separating_left NormedSpace.dualPairing_separatingLeft end General section BidualIsometry variable (๐•œ : Type v) [IsROrC ๐•œ] {E : Type u} [NormedAddCommGroup E] [NormedSpace ๐•œ E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `ContinuousLinearMap.op_norm_le_bound`. -/ theorem norm_le_dual_bound (x : E) {M : โ„} (hMp : 0 โ‰ค M) (hM : โˆ€ f : Dual ๐•œ E, โ€–f xโ€– โ‰ค M * โ€–fโ€–) : โ€–xโ€– โ‰ค M := by classical by_cases h : x = 0 ยท simp only [h, hMp, norm_zero] ยท obtain โŸจf, hfโ‚, hfxโŸฉ : โˆƒ f : E โ†’L[๐•œ] ๐•œ, โ€–fโ€– = 1 โˆง f x = โ€–xโ€– := exists_dual_vector ๐•œ x h calc โ€–xโ€– = โ€–(โ€–xโ€– : ๐•œ)โ€– := IsROrC.norm_coe_norm.symm _ = โ€–f xโ€– := by rw [hfx] _ โ‰ค M * โ€–fโ€– := (hM f) _ = M := by rw [hfโ‚, mul_one] #align normed_space.norm_le_dual_bound NormedSpace.norm_le_dual_bound theorem eq_zero_of_forall_dual_eq_zero {x : E} (h : โˆ€ f : Dual ๐•œ E, f x = (0 : ๐•œ)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound ๐•œ x le_rfl fun f => by simp [h f]) #align normed_space.eq_zero_of_forall_dual_eq_zero NormedSpace.eq_zero_of_forall_dual_eq_zero theorem eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 โ†” โˆ€ g : Dual ๐•œ E, g x = 0 := โŸจfun hx => by simp [hx], fun h => eq_zero_of_forall_dual_eq_zero ๐•œ hโŸฉ #align normed_space.eq_zero_iff_forall_dual_eq_zero NormedSpace.eq_zero_iff_forall_dual_eq_zero /-- See also `geometric_hahn_banach_point_point`. -/ theorem eq_iff_forall_dual_eq {x y : E} : x = y โ†” โˆ€ g : Dual ๐•œ E, g x = g y := by rw [โ† sub_eq_zero, eq_zero_iff_forall_dual_eq_zero ๐•œ (x - y)] simp [sub_eq_zero] #align normed_space.eq_iff_forall_dual_eq NormedSpace.eq_iff_forall_dual_eq /-- The inclusion of a normed space in its double dual is an isometry onto its image.-/ def inclusionInDoubleDualLi : E โ†’โ‚—แตข[๐•œ] Dual ๐•œ (Dual ๐•œ E) := { inclusionInDoubleDual ๐•œ E with norm_map' := by intro x apply le_antisymm ยท exact double_dual_bound ๐•œ E x rw [ContinuousLinearMap.norm_def] refine' le_csInf ContinuousLinearMap.bounds_nonempty _ rintro c โŸจhc1, hc2โŸฉ exact norm_le_dual_bound ๐•œ x hc1 hc2 } #align normed_space.inclusion_in_double_dual_li NormedSpace.inclusionInDoubleDualLi end BidualIsometry section PolarSets open Metric Set NormedSpace /-- Given a subset `s` in a normed space `E` (over a field `๐•œ`), the polar `polar ๐•œ s` is the subset of `Dual ๐•œ E` consisting of those functionals which evaluate to something of norm at most one at all points `z โˆˆ s`. -/ def polar (๐•œ : Type*) [NontriviallyNormedField ๐•œ] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] : Set E โ†’ Set (Dual ๐•œ E) := (dualPairing ๐•œ E).flip.polar #align normed_space.polar NormedSpace.polar variable (๐•œ : Type*) [NontriviallyNormedField ๐•œ] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ๐•œ E] theorem mem_polar_iff {x' : Dual ๐•œ E} (s : Set E) : x' โˆˆ polar ๐•œ s โ†” โˆ€ z โˆˆ s, โ€–x' zโ€– โ‰ค 1 := Iff.rfl #align normed_space.mem_polar_iff NormedSpace.mem_polar_iff @[simp] theorem polar_univ : polar ๐•œ (univ : Set E) = {(0 : Dual ๐•œ E)} := (dualPairing ๐•œ E).flip.polar_univ (LinearMap.flip_separatingRight.mpr (dualPairing_separatingLeft ๐•œ E)) #align normed_space.polar_univ NormedSpace.polar_univ theorem isClosed_polar (s : Set E) : IsClosed (polar ๐•œ s) := by dsimp only [NormedSpace.polar] simp only [LinearMap.polar_eq_iInter, LinearMap.flip_apply] refine' isClosed_biInter fun z _ => _ exact isClosed_Iic.preimage (ContinuousLinearMap.apply ๐•œ ๐•œ z).continuous.norm #align normed_space.is_closed_polar NormedSpace.isClosed_polar @[simp] theorem polar_closure (s : Set E) : polar ๐•œ (closure s) = polar ๐•œ s := ((dualPairing ๐•œ E).flip.polar_antitone subset_closure).antisymm <| (dualPairing ๐•œ E).flip.polar_gc.l_le <| closure_minimal ((dualPairing ๐•œ E).flip.polar_gc.le_u_l s) <| by simpa [LinearMap.flip_flip] using (isClosed_polar _ _).preimage (inclusionInDoubleDual ๐•œ E).continuous #align normed_space.polar_closure NormedSpace.polar_closure variable {๐•œ} /-- If `x'` is a dual element such that the norms `โ€–x' zโ€–` are bounded for `z โˆˆ s`, then a small scalar multiple of `x'` is in `polar ๐•œ s`. -/ theorem smul_mem_polar {s : Set E} {x' : Dual ๐•œ E} {c : ๐•œ} (hc : โˆ€ z, z โˆˆ s โ†’ โ€–x' zโ€– โ‰ค โ€–cโ€–) : cโปยน โ€ข x' โˆˆ polar ๐•œ s := by by_cases c_zero : c = 0 ยท simp only [c_zero, inv_zero, zero_smul] exact (dualPairing ๐•œ E).flip.zero_mem_polar _ have eq : โˆ€ z, โ€–cโปยน โ€ข x' zโ€– = โ€–cโปยนโ€– * โ€–x' zโ€– := fun z => norm_smul cโปยน _ have le : โˆ€ z, z โˆˆ s โ†’ โ€–cโปยน โ€ข x' zโ€– โ‰ค โ€–cโปยนโ€– * โ€–cโ€– := by intro z hzs rw [eq z] apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _) have cancel : โ€–cโปยนโ€– * โ€–cโ€– = 1 := by simp only [c_zero, norm_eq_zero, Ne.def, not_false_iff, inv_mul_cancel, norm_inv] rwa [cancel] at le #align normed_space.smul_mem_polar NormedSpace.smul_mem_polar theorem polar_ball_subset_closedBall_div {c : ๐•œ} (hc : 1 < โ€–cโ€–) {r : โ„} (hr : 0 < r) : polar ๐•œ (ball (0 : E) r) โІ closedBall (0 : Dual ๐•œ E) (โ€–cโ€– / r) := by intro x' hx' rw [mem_polar_iff] at hx' simp only [polar, mem_setOf, mem_closedBall_zero_iff, mem_ball_zero_iff] at * have hcr : 0 < โ€–cโ€– / r := div_pos (zero_lt_one.trans hc) hr refine' ContinuousLinearMap.op_norm_le_of_shell hr hcr.le hc fun x hโ‚ hโ‚‚ => _ calc โ€–x' xโ€– โ‰ค 1 := hx' _ hโ‚‚ _ โ‰ค โ€–cโ€– / r * โ€–xโ€– := (inv_pos_le_iff_one_le_mul' hcr).1 (by rwa [inv_div]) #align normed_space.polar_ball_subset_closed_ball_div NormedSpace.polar_ball_subset_closedBall_div variable (๐•œ) theorem closedBall_inv_subset_polar_closedBall {r : โ„} : closedBall (0 : Dual ๐•œ E) rโปยน โІ polar ๐•œ (closedBall (0 : E) r) := fun x' hx' x hx => calc โ€–x' xโ€– โ‰ค โ€–x'โ€– * โ€–xโ€– := x'.le_op_norm x _ โ‰ค rโปยน * r := (mul_le_mul (mem_closedBall_zero_iff.1 hx') (mem_closedBall_zero_iff.1 hx) (norm_nonneg _) (dist_nonneg.trans hx')) _ = r / r := (inv_mul_eq_div _ _) _ โ‰ค 1 := div_self_le_one r #align normed_space.closed_ball_inv_subset_polar_closed_ball NormedSpace.closedBall_inv_subset_polar_closedBall /-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {๐•œ E : Type*} [IsROrC ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] {r : โ„} (hr : 0 < r) : polar ๐•œ (closedBall (0 : E) r) = closedBall (0 : Dual ๐•œ E) rโปยน := by refine' Subset.antisymm _ (closedBall_inv_subset_polar_closedBall ๐•œ) intro x' h simp only [mem_closedBall_zero_iff] refine' ContinuousLinearMap.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) fun z _ => _ simpa only [one_div] using LinearMap.bound_of_ball_bound' hr 1 x'.toLinearMap h z #align normed_space.polar_closed_ball NormedSpace.polar_closedBall /-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s) := by obtain โŸจa, haโŸฉ : โˆƒ a : ๐•œ, 1 < โ€–aโ€– := NormedField.exists_one_lt_norm ๐•œ obtain โŸจr, r_pos, r_ballโŸฉ : โˆƒ r : โ„, 0 < r โˆง ball 0 r โІ s := Metric.mem_nhds_iff.1 s_nhd
exact isBounded_closedBall.subset (((dualPairing ๐•œ E).flip.polar_antitone r_ball).trans <| polar_ball_subset_closedBall_div ha r_pos)
/-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s) := by obtain โŸจa, haโŸฉ : โˆƒ a : ๐•œ, 1 < โ€–aโ€– := NormedField.exists_one_lt_norm ๐•œ obtain โŸจr, r_pos, r_ballโŸฉ : โˆƒ r : โ„, 0 < r โˆง ball 0 r โІ s := Metric.mem_nhds_iff.1 s_nhd
Mathlib.Analysis.NormedSpace.Dual.254_0.WirVfj6f5oiZZ2w
/-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar ๐•œ s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhd : s โˆˆ ๐“ (0 : E)) : IsBounded (polar ๐•œ s)
Mathlib_Analysis_NormedSpace_Dual
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r โŠข CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ fun x x_1 => x โ‰  x_1) fun x x_1 => x < x_1) โ‡‘toFinsupp
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by
rintro s t โŸจu, a, hr, heโŸฉ
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ u, r a' a he : s + {a} = t + u โŠข InvImage (Finsupp.Lex (rแถœ โŠ“ fun x x_1 => x โ‰  x_1) fun x x_1 => x < x_1) (โ‡‘toFinsupp) s t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ
replace hr := fun a' โ†ฆ mt (hr a')
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ he : s + {a} = t + u hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u โŠข InvImage (Finsupp.Lex (rแถœ โŠ“ fun x x_1 => x โ‰  x_1) fun x x_1 => x < x_1) (โ‡‘toFinsupp) s t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a')
classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a')
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ he : s + {a} = t + u hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u โŠข InvImage (Finsupp.Lex (rแถœ โŠ“ fun x x_1 => x โ‰  x_1) fun x x_1 => x < x_1) (โ‡‘toFinsupp) s t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical
refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro.refine_1 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ he : s + {a} = t + u hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u b : ฮฑ h : (rแถœ โŠ“ fun x x_1 => x โ‰  x_1) b a โŠข (toFinsupp s) b = (toFinsupp t) b
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;>
simp_rw [toFinsupp_apply]
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;>
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro.refine_2 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ he : s + {a} = t + u hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u โŠข (fun {i} x x_1 => x < x_1) ((toFinsupp s) a) ((toFinsupp t) a)
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;>
simp_rw [toFinsupp_apply]
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;>
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro.refine_1 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ he : s + {a} = t + u hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u b : ฮฑ h : (rแถœ โŠ“ fun x x_1 => x โ‰  x_1) b a โŠข count b s = count b t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท
apply_fun count b at he
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro.refine_1 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u b : ฮฑ h : (rแถœ โŠ“ fun x x_1 => x โ‰  x_1) b a he : count b (s + {a}) = count b (t + u) โŠข count b s = count b t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he
simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro.refine_2 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ he : s + {a} = t + u hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u โŠข count a s < count a t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท
apply_fun count a at he
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro.refine_2 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u he : count a (s + {a}) = count a (t + u) โŠข count a s < count a t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he
simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
case intro.intro.intro.refine_2 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t u : Multiset ฮฑ a : ฮฑ hr : โˆ€ (a' : ฮฑ), ยฌr a' a โ†’ a' โˆ‰ u he : count a s + 1 = count a t โŠข count a s < count a t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he
exact he โ–ธ Nat.lt_succ_self _
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he
Mathlib.Logic.Hydra.62_0.cWRHz2gehQLFc75
theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop x' x : ฮฑ hโœ : r x' x a : ฮฑ h : a โˆˆ {x'} โŠข r a x
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by
rwa [mem_singleton.1 h]
theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by
Mathlib.Logic.Hydra.81_0.cWRHz2gehQLFc75
theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x}
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop t u s xโœยน : Multiset ฮฑ xโœ : ฮฑ โŠข s + t + {xโœ} = s + u + xโœยน โ†” t + {xโœ} = u + xโœยน
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by
rw [add_assoc, add_assoc, add_left_cancel_iff]
theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by
Mathlib.Logic.Hydra.85_0.cWRHz2gehQLFc75
theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s' s : Multiset ฮฑ โŠข CutExpand r s' s โ†” โˆƒ t a, (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = erase s a + t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by
simp_rw [CutExpand, add_singleton_eq_iff]
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by
Mathlib.Logic.Hydra.89_0.cWRHz2gehQLFc75
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s' s : Multiset ฮฑ โŠข (โˆƒ t a, (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s + t โˆง s' = erase (s + t) a) โ†” โˆƒ t a, (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = erase s a + t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff]
refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff]
Mathlib.Logic.Hydra.89_0.cWRHz2gehQLFc75
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t
Mathlib_Logic_Hydra
case refine'_1 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s' s t : Multiset ฮฑ a : ฮฑ โŠข (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s + t โˆง s' = erase (s + t) a โ†’ (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = erase s a + t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท
rintro โŸจht, ha, rflโŸฉ
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท
Mathlib.Logic.Hydra.89_0.cWRHz2gehQLFc75
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t
Mathlib_Logic_Hydra
case refine'_1.intro.intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t : Multiset ฮฑ a : ฮฑ ht : โˆ€ a' โˆˆ t, r a' a ha : a โˆˆ s + t โŠข (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง erase (s + t) a = erase s a + t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ
obtain h | h := mem_add.1 ha
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ
Mathlib.Logic.Hydra.89_0.cWRHz2gehQLFc75
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t
Mathlib_Logic_Hydra
case refine'_1.intro.intro.inl ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t : Multiset ฮฑ a : ฮฑ ht : โˆ€ a' โˆˆ t, r a' a ha : a โˆˆ s + t h : a โˆˆ s โŠข (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง erase (s + t) a = erase s a + t case refine'_1.intro.intro.inr ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t : Multiset ฮฑ a : ฮฑ ht : โˆ€ a' โˆˆ t, r a' a ha : a โˆˆ s + t h : a โˆˆ t โŠข (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง erase (s + t) a = erase s a + t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha
exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim]
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha
Mathlib.Logic.Hydra.89_0.cWRHz2gehQLFc75
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t
Mathlib_Logic_Hydra
case refine'_2 ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s' s t : Multiset ฮฑ a : ฮฑ โŠข (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = erase s a + t โ†’ (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s + t โˆง s' = erase (s + t) a
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท
rintro โŸจht, h, rflโŸฉ
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท
Mathlib.Logic.Hydra.89_0.cWRHz2gehQLFc75
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t
Mathlib_Logic_Hydra
case refine'_2.intro.intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœยน : DecidableEq ฮฑ instโœ : IsIrrefl ฮฑ r s t : Multiset ฮฑ a : ฮฑ ht : โˆ€ a' โˆˆ t, r a' a h : a โˆˆ s โŠข (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s + t โˆง erase s a + t = erase (s + t) a
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ
exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ
Mathlib.Logic.Hydra.89_0.cWRHz2gehQLFc75
theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r s : Multiset ฮฑ โŠข ยฌCutExpand r s 0
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by
classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ
theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by
Mathlib.Logic.Hydra.101_0.cWRHz2gehQLFc75
theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r s : Multiset ฮฑ โŠข ยฌCutExpand r s 0
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical
rw [cutExpand_iff]
theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical
Mathlib.Logic.Hydra.101_0.cWRHz2gehQLFc75
theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r s : Multiset ฮฑ โŠข ยฌโˆƒ t a, (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ 0 โˆง s = erase 0 a + t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff]
rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ
theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff]
Mathlib.Logic.Hydra.101_0.cWRHz2gehQLFc75
theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0
Mathlib_Logic_Hydra
ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop โŠข Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s => s.1 + s.2
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by
rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ s t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : s + {a} = (fun s => s.1 + s.2) (sโ‚, sโ‚‚) + t โŠข โˆƒ a', GameAdd (CutExpand r) (CutExpand r) a' (sโ‚, sโ‚‚) โˆง (fun s => s.1 + s.2) a' = s
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ;
dsimp at he โŠข
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ;
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ s t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : s + {a} = sโ‚ + sโ‚‚ + t โŠข โˆƒ a', GameAdd (CutExpand r) (CutExpand r) a' (sโ‚, sโ‚‚) โˆง a'.1 + a'.2 = s
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข
classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h]
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ s t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : s + {a} = sโ‚ + sโ‚‚ + t โŠข โˆƒ a', GameAdd (CutExpand r) (CutExpand r) a' (sโ‚, sโ‚‚) โˆง a'.1 + a'.2 = s
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical
obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro.intro ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a ha : a โˆˆ sโ‚ + sโ‚‚ + t he : erase (sโ‚ + sโ‚‚ + t) a + {a} = sโ‚ + sโ‚‚ + t โŠข โˆƒ a', GameAdd (CutExpand r) (CutExpand r) a' (sโ‚, sโ‚‚) โˆง a'.1 + a'.2 = erase (sโ‚ + sโ‚‚ + t) a
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he
rw [add_assoc, mem_add] at ha
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro.intro ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a ha : a โˆˆ sโ‚ โˆจ a โˆˆ sโ‚‚ + t he : erase (sโ‚ + sโ‚‚ + t) a + {a} = sโ‚ + sโ‚‚ + t โŠข โˆƒ a', GameAdd (CutExpand r) (CutExpand r) a' (sโ‚, sโ‚‚) โˆง a'.1 + a'.2 = erase (sโ‚ + sโ‚‚ + t) a
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha
obtain h | h := ha
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro.intro.inl ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : erase (sโ‚ + sโ‚‚ + t) a + {a} = sโ‚ + sโ‚‚ + t h : a โˆˆ sโ‚ โŠข โˆƒ a', GameAdd (CutExpand r) (CutExpand r) a' (sโ‚, sโ‚‚) โˆง a'.1 + a'.2 = erase (sโ‚ + sโ‚‚ + t) a
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท
refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro.intro.inl.refine'_1 ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : erase (sโ‚ + sโ‚‚ + t) a + {a} = sโ‚ + sโ‚‚ + t h : a โˆˆ sโ‚ โŠข erase sโ‚ a + t + {a} = sโ‚ + t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท
rw [add_comm, โ† add_assoc, singleton_add, cons_erase h]
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro.intro.inl.refine'_2 ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : erase (sโ‚ + sโ‚‚ + t) a + {a} = sโ‚ + sโ‚‚ + t h : a โˆˆ sโ‚ โŠข (erase sโ‚ a + t, sโ‚‚).1 + (erase sโ‚ a + t, sโ‚‚).2 = erase (sโ‚ + sโ‚‚ + t) a
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท
rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc]
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro.intro.inr ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : erase (sโ‚ + sโ‚‚ + t) a + {a} = sโ‚ + sโ‚‚ + t h : a โˆˆ sโ‚‚ + t โŠข โˆƒ a', GameAdd (CutExpand r) (CutExpand r) a' (sโ‚, sโ‚‚) โˆง a'.1 + a'.2 = erase (sโ‚ + sโ‚‚ + t) a
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท
refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro.intro.inr.refine'_1 ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : erase (sโ‚ + sโ‚‚ + t) a + {a} = sโ‚ + sโ‚‚ + t h : a โˆˆ sโ‚‚ + t โŠข erase (sโ‚‚ + t) a + {a} = sโ‚‚ + t
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท
rw [add_comm, singleton_add, cons_erase h]
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
case mk.intro.intro.intro.intro.inr.refine'_2 ฮฑ : Type u_1 rโœ r : ฮฑ โ†’ ฮฑ โ†’ Prop sโ‚ sโ‚‚ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a he : erase (sโ‚ + sโ‚‚ + t) a + {a} = sโ‚ + sโ‚‚ + t h : a โˆˆ sโ‚‚ + t โŠข (sโ‚, erase (sโ‚‚ + t) a).1 + (sโ‚, erase (sโ‚‚ + t) a).2 = erase (sโ‚ + sโ‚‚ + t) a
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท
rw [add_assoc, erase_add_right_pos _ h]
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท
Mathlib.Logic.Hydra.107_0.cWRHz2gehQLFc75
/-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r s : Multiset ฮฑ hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a} โŠข Acc (CutExpand r) s
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by
induction s using Multiset.induction
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
case empty ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r hs : โˆ€ a โˆˆ 0, Acc (CutExpand r) {a} โŠข Acc (CutExpand r) 0 case cons ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœยน : ฮฑ sโœ : Multiset ฮฑ aโœ : (โˆ€ a โˆˆ sโœ, Acc (CutExpand r) {a}) โ†’ Acc (CutExpand r) sโœ hs : โˆ€ a โˆˆ aโœยน ::โ‚˜ sโœ, Acc (CutExpand r) {a} โŠข Acc (CutExpand r) (aโœยน ::โ‚˜ sโœ)
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction
case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r hs : โˆ€ a โˆˆ 0, Acc (CutExpand r) {a} โŠข Acc (CutExpand r) 0
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction
case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r hs : โˆ€ a โˆˆ 0, Acc (CutExpand r) {a} โŠข Acc (CutExpand r) 0
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty =>
exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty =>
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
case cons ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœยน : ฮฑ sโœ : Multiset ฮฑ aโœ : (โˆ€ a โˆˆ sโœ, Acc (CutExpand r) {a}) โ†’ Acc (CutExpand r) sโœ hs : โˆ€ a โˆˆ aโœยน ::โ‚˜ sโœ, Acc (CutExpand r) {a} โŠข Acc (CutExpand r) (aโœยน ::โ‚˜ sโœ)
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim
case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r)
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r a : ฮฑ s : Multiset ฮฑ ihs : (โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) โ†’ Acc (CutExpand r) s hs : โˆ€ a_1 โˆˆ a ::โ‚˜ s, Acc (CutExpand r) {a_1} โŠข Acc (CutExpand r) (a ::โ‚˜ s)
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim
case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r)
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r a : ฮฑ s : Multiset ฮฑ ihs : (โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) โ†’ Acc (CutExpand r) s hs : โˆ€ a_1 โˆˆ a ::โ‚˜ s, Acc (CutExpand r) {a_1} โŠข Acc (CutExpand r) (a ::โ‚˜ s)
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs =>
rw [โ† s.singleton_add a]
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs =>
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r a : ฮฑ s : Multiset ฮฑ ihs : (โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) โ†’ Acc (CutExpand r) s hs : โˆ€ a_1 โˆˆ a ::โ‚˜ s, Acc (CutExpand r) {a_1} โŠข Acc (CutExpand r) ({a} + s)
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a]
rw [forall_mem_cons] at hs
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a]
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r a : ฮฑ s : Multiset ฮฑ ihs : (โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) โ†’ Acc (CutExpand r) s hs : Acc (CutExpand r) {a} โˆง โˆ€ x โˆˆ s, Acc (CutExpand r) {x} โŠข Acc (CutExpand r) ({a} + s)
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs
exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r)
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs
Mathlib.Logic.Hydra.124_0.cWRHz2gehQLFc75
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s
Mathlib_Logic_Hydra
ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r a : ฮฑ hacc : Acc r a โŠข Acc (CutExpand r) {a}
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r) #align relation.acc_of_singleton Relation.acc_of_singleton /-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by
induction' hacc with a h ih
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by
Mathlib.Logic.Hydra.136_0.cWRHz2gehQLFc75
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a}
Mathlib_Logic_Hydra
case intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœ a : ฮฑ h : โˆ€ (y : ฮฑ), r y a โ†’ Acc r y ih : โˆ€ (y : ฮฑ), r y a โ†’ Acc (CutExpand r) {y} โŠข Acc (CutExpand r) {a}
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r) #align relation.acc_of_singleton Relation.acc_of_singleton /-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih
refine' Acc.intro _ fun s โ†ฆ _
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih
Mathlib.Logic.Hydra.136_0.cWRHz2gehQLFc75
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a}
Mathlib_Logic_Hydra
case intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœ a : ฮฑ h : โˆ€ (y : ฮฑ), r y a โ†’ Acc r y ih : โˆ€ (y : ฮฑ), r y a โ†’ Acc (CutExpand r) {y} s : Multiset ฮฑ โŠข CutExpand r s {a} โ†’ Acc (CutExpand r) s
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r) #align relation.acc_of_singleton Relation.acc_of_singleton /-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _
classical simp only [cutExpand_iff, mem_singleton] rintro โŸจt, a, hr, rfl, rflโŸฉ refine' acc_of_singleton fun a' โ†ฆ _ rw [erase_singleton, zero_add] exact ih a' โˆ˜ hr a'
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _
Mathlib.Logic.Hydra.136_0.cWRHz2gehQLFc75
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a}
Mathlib_Logic_Hydra
case intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœ a : ฮฑ h : โˆ€ (y : ฮฑ), r y a โ†’ Acc r y ih : โˆ€ (y : ฮฑ), r y a โ†’ Acc (CutExpand r) {y} s : Multiset ฮฑ โŠข CutExpand r s {a} โ†’ Acc (CutExpand r) s
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r) #align relation.acc_of_singleton Relation.acc_of_singleton /-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical
simp only [cutExpand_iff, mem_singleton]
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical
Mathlib.Logic.Hydra.136_0.cWRHz2gehQLFc75
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a}
Mathlib_Logic_Hydra
case intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœ a : ฮฑ h : โˆ€ (y : ฮฑ), r y a โ†’ Acc r y ih : โˆ€ (y : ฮฑ), r y a โ†’ Acc (CutExpand r) {y} s : Multiset ฮฑ โŠข (โˆƒ t a_1, (โˆ€ a' โˆˆ t, r a' a_1) โˆง a_1 = a โˆง s = erase {a} a_1 + t) โ†’ Acc (CutExpand r) s
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r) #align relation.acc_of_singleton Relation.acc_of_singleton /-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical simp only [cutExpand_iff, mem_singleton]
rintro โŸจt, a, hr, rfl, rflโŸฉ
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical simp only [cutExpand_iff, mem_singleton]
Mathlib.Logic.Hydra.136_0.cWRHz2gehQLFc75
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a}
Mathlib_Logic_Hydra
case intro.intro.intro.intro.intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœ : ฮฑ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a h : โˆ€ (y : ฮฑ), r y a โ†’ Acc r y ih : โˆ€ (y : ฮฑ), r y a โ†’ Acc (CutExpand r) {y} โŠข Acc (CutExpand r) (erase {a} a + t)
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r) #align relation.acc_of_singleton Relation.acc_of_singleton /-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical simp only [cutExpand_iff, mem_singleton] rintro โŸจt, a, hr, rfl, rflโŸฉ
refine' acc_of_singleton fun a' โ†ฆ _
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical simp only [cutExpand_iff, mem_singleton] rintro โŸจt, a, hr, rfl, rflโŸฉ
Mathlib.Logic.Hydra.136_0.cWRHz2gehQLFc75
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a}
Mathlib_Logic_Hydra
case intro.intro.intro.intro.intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœ : ฮฑ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a h : โˆ€ (y : ฮฑ), r y a โ†’ Acc r y ih : โˆ€ (y : ฮฑ), r y a โ†’ Acc (CutExpand r) {y} a' : ฮฑ โŠข a' โˆˆ erase {a} a + t โ†’ Acc (CutExpand r) {a'}
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r) #align relation.acc_of_singleton Relation.acc_of_singleton /-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical simp only [cutExpand_iff, mem_singleton] rintro โŸจt, a, hr, rfl, rflโŸฉ refine' acc_of_singleton fun a' โ†ฆ _
rw [erase_singleton, zero_add]
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical simp only [cutExpand_iff, mem_singleton] rintro โŸจt, a, hr, rfl, rflโŸฉ refine' acc_of_singleton fun a' โ†ฆ _
Mathlib.Logic.Hydra.136_0.cWRHz2gehQLFc75
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a}
Mathlib_Logic_Hydra
case intro.intro.intro.intro.intro ฮฑ : Type u_1 r : ฮฑ โ†’ ฮฑ โ†’ Prop instโœ : IsIrrefl ฮฑ r aโœ : ฮฑ t : Multiset ฮฑ a : ฮฑ hr : โˆ€ a' โˆˆ t, r a' a h : โˆ€ (y : ฮฑ), r y a โ†’ Acc r y ih : โˆ€ (y : ฮฑ), r y a โ†’ Acc (CutExpand r) {y} a' : ฮฑ โŠข a' โˆˆ t โ†’ Acc (CutExpand r) {a'}
/- Copyright (c) 2022 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.GameAdd #align_import logic.hydra from "leanprover-community/mathlib"@"48085f140e684306f9e7da907cd5932056d1aded" /-! # Termination of a hydra game This file deals with the following version of the hydra game: each head of the hydra is labelled by an element in a type `ฮฑ`, and when you cut off one head with label `a`, it grows back an arbitrary but finite number of heads, all labelled by elements smaller than `a` with respect to a well-founded relation `r` on `ฮฑ`. We show that no matter how (in what order) you choose cut off the heads, the game always terminates, i.e. all heads will eventually be cut off (but of course it can last arbitrarily long, i.e. takes an arbitrary finite number of steps). This result is stated as the well-foundedness of the `CutExpand` relation defined in this file: we model the heads of the hydra as a multiset of elements of `ฮฑ`, and the valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset ฮฑ`: `CutExpand r s' s` is true iff `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332. TODO: formalize the relations corresponding to more powerful (e.g. Kirbyโ€“Paris and Buchholz) hydras, and prove their well-foundedness. -/ namespace Relation open Multiset Prod variable {ฮฑ : Type*} /-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s` means that `s'` is obtained by removing one head `a โˆˆ s` and adding back an arbitrary multiset `t` of heads such that all `a' โˆˆ t` satisfy `r a' a`. This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires `DecidableEq ฮฑ`, so we use the equivalent condition `s' + {a} = s + t` instead, which is also easier to verify for explicit multisets `s'`, `s` and `t`. We also don't include the condition `a โˆˆ s` because `s' + {a} = s + t` already guarantees `a โˆˆ s + t`, and if `r` is irreflexive then `a โˆ‰ t`, which is the case when `r` is well-founded, the case we are primarily interested in. The lemma `Relation.cutExpand_iff` below converts between this convenient definition and the direct translation when `r` is irreflexive. -/ def CutExpand (r : ฮฑ โ†’ ฮฑ โ†’ Prop) (s' s : Multiset ฮฑ) : Prop := โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง s' + {a} = s + t #align relation.cut_expand Relation.CutExpand variable {r : ฮฑ โ†’ ฮฑ โ†’ Prop} theorem cutExpand_le_invImage_lex [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] : CutExpand r โ‰ค InvImage (Finsupp.Lex (rแถœ โŠ“ (ยท โ‰  ยท)) (ยท < ยท)) toFinsupp := by rintro s t โŸจu, a, hr, heโŸฉ replace hr := fun a' โ†ฆ mt (hr a') classical refine โŸจa, fun b h โ†ฆ ?_, ?_โŸฉ <;> simp_rw [toFinsupp_apply] ยท apply_fun count b at he simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)] using he ยท apply_fun count a at he simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)), add_zero] at he exact he โ–ธ Nat.lt_succ_self _ #align relation.cut_expand_le_inv_image_lex Relation.cutExpand_le_invImage_lex theorem cutExpand_singleton {s x} (h : โˆ€ x' โˆˆ s, r x' x) : CutExpand r s {x} := โŸจs, x, h, add_comm s _โŸฉ #align relation.cut_expand_singleton Relation.cutExpand_singleton theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} := cutExpand_singleton fun a h โ†ฆ by rwa [mem_singleton.1 h] #align relation.cut_expand_singleton_singleton Relation.cutExpand_singleton_singleton theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) โ†” CutExpand r t u := existsโ‚‚_congr fun _ _ โ†ฆ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff] #align relation.cut_expand_add_left Relation.cutExpand_add_left theorem cutExpand_iff [DecidableEq ฮฑ] [IsIrrefl ฮฑ r] {s' s : Multiset ฮฑ} : CutExpand r s' s โ†” โˆƒ (t : Multiset ฮฑ) (a : ฮฑ), (โˆ€ a' โˆˆ t, r a' a) โˆง a โˆˆ s โˆง s' = s.erase a + t := by simp_rw [CutExpand, add_singleton_eq_iff] refine' existsโ‚‚_congr fun t a โ†ฆ โŸจ_, _โŸฉ ยท rintro โŸจht, ha, rflโŸฉ obtain h | h := mem_add.1 ha exacts [โŸจht, h, erase_add_left_pos t hโŸฉ, (@irrefl ฮฑ r _ a (ht a h)).elim] ยท rintro โŸจht, h, rflโŸฉ exact โŸจht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symmโŸฉ #align relation.cut_expand_iff Relation.cutExpand_iff theorem not_cutExpand_zero [IsIrrefl ฮฑ r] (s) : ยฌCutExpand r s 0 := by classical rw [cutExpand_iff] rintro โŸจ_, _, _, โŸจโŸฉ, _โŸฉ #align relation.not_cut_expand_zero Relation.not_cutExpand_zero /-- For any relation `r` on `ฮฑ`, multiset addition `Multiset ฮฑ ร— Multiset ฮฑ โ†’ Multiset ฮฑ` is a fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/ theorem cutExpand_fibration (r : ฮฑ โ†’ ฮฑ โ†’ Prop) : Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s โ†ฆ s.1 + s.2 := by rintro โŸจsโ‚, sโ‚‚โŸฉ s โŸจt, a, hr, heโŸฉ; dsimp at he โŠข classical obtain โŸจha, rflโŸฉ := add_singleton_eq_iff.1 he rw [add_assoc, mem_add] at ha obtain h | h := ha ยท refine' โŸจ(sโ‚.erase a + t, sโ‚‚), GameAdd.fst โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, โ† add_assoc, singleton_add, cons_erase h] ยท rw [add_assoc sโ‚, erase_add_left_pos _ h, add_right_comm, add_assoc] ยท refine' โŸจ(sโ‚, (sโ‚‚ + t).erase a), GameAdd.snd โŸจt, a, hr, _โŸฉ, _โŸฉ ยท rw [add_comm, singleton_add, cons_erase h] ยท rw [add_assoc, erase_add_right_pos _ h] #align relation.cut_expand_fibration Relation.cutExpand_fibration /-- A multiset is accessible under `CutExpand` if all its singleton subsets are, assuming `r` is irreflexive. -/ theorem acc_of_singleton [IsIrrefl ฮฑ r] {s : Multiset ฮฑ} (hs : โˆ€ a โˆˆ s, Acc (CutExpand r) {a}) : Acc (CutExpand r) s := by induction s using Multiset.induction case empty => exact Acc.intro 0 fun s h โ†ฆ (not_cutExpand_zero s h).elim case cons a s ihs => rw [โ† s.singleton_add a] rw [forall_mem_cons] at hs exact (hs.1.prod_gameAdd <| ihs fun a ha โ†ฆ hs.2 a ha).of_fibration _ (cutExpand_fibration r) #align relation.acc_of_singleton Relation.acc_of_singleton /-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical simp only [cutExpand_iff, mem_singleton] rintro โŸจt, a, hr, rfl, rflโŸฉ refine' acc_of_singleton fun a' โ†ฆ _ rw [erase_singleton, zero_add]
exact ih a' โˆ˜ hr a'
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a} := by induction' hacc with a h ih refine' Acc.intro _ fun s โ†ฆ _ classical simp only [cutExpand_iff, mem_singleton] rintro โŸจt, a, hr, rfl, rflโŸฉ refine' acc_of_singleton fun a' โ†ฆ _ rw [erase_singleton, zero_add]
Mathlib.Logic.Hydra.136_0.cWRHz2gehQLFc75
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`, assuming `r` is irreflexive. -/ theorem _root_.Acc.cutExpand [IsIrrefl ฮฑ r] {a : ฮฑ} (hacc : Acc r a) : Acc (CutExpand r) {a}
Mathlib_Logic_Hydra
Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m n : โ„• R : Type u_1 instโœ : CommSemiring R x y : R โŠข (x + y) ^ 0 = x ^ 0 + โ†‘0 * x ^ (0 - 1) * y + 0 * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by
simp
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m n : โ„• R : Type u_1 instโœ : CommSemiring R x y : R โŠข (x + y) ^ 1 = x ^ 1 + โ†‘1 * x ^ (1 - 1) * y + 0 * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by
simp
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m nโœ : โ„• R : Type u_1 instโœ : CommSemiring R x y : R n : โ„• โŠข { k // (x + y) ^ (n + 2) = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 2 - 1) * y + k * y ^ 2 }
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by
cases' (powAddExpansion x y (n + 1)) with z hz
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
case mk Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m nโœ : โ„• R : Type u_1 instโœ : CommSemiring R x y : R n : โ„• z : R hz : (x + y) ^ (n + 1) = x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2 โŠข { k // (x + y) ^ (n + 2) = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 2 - 1) * y + k * y ^ 2 }
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz
exists x * z + (n + 1) * x ^ n + z * y
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
case mk Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m nโœ : โ„• R : Type u_1 instโœ : CommSemiring R x y : R n : โ„• z : R hz : (x + y) ^ (n + 1) = x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2 โŠข (x + y) ^ (n + 2) = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 2 - 1) * y + (x * z + (โ†‘n + 1) * x ^ n + z * y) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y
calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring!
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m nโœ : โ„• R : Type u_1 instโœ : CommSemiring R x y : R n : โ„• z : R hz : (x + y) ^ (n + 1) = x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2 โŠข (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by
ring
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m nโœ : โ„• R : Type u_1 instโœ : CommSemiring R x y : R n : โ„• z : R hz : (x + y) ^ (n + 1) = x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2 โŠข (x + y) * (x + y) ^ (n + 1) = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by
rw [hz]
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m nโœ : โ„• R : Type u_1 instโœ : CommSemiring R x y : R n : โ„• z : R hz : (x + y) ^ (n + 1) = x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2 โŠข (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (โ†‘n + 1) * x ^ n + z * y) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by
push_cast
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
Rโœ : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : Rโœ m nโœ : โ„• R : Type u_1 instโœ : CommSemiring R x y : R n : โ„• z : R hz : (x + y) ^ (n + 1) = x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2 โŠข (x + y) * (x ^ (n + 1) + (โ†‘n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) = x ^ (n + 2) + (โ†‘n + 2) * x ^ (n + 1) * y + (x * z + (โ†‘n + 1) * x ^ n + z * y) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast
ring!
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast
Mathlib.Data.Polynomial.Identities.37_0.o6IrpyrTENfZuiK
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1)
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z aโœ b : R m n : โ„• instโœ : CommRing R x y : R e : โ„• a : R โŠข { k // a * (x + y) ^ e = a * (x ^ e + โ†‘e * x ^ (e - 1) * y + k * y ^ 2) }
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by
exists (powAddExpansion x y e).val
private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by
Mathlib.Data.Polynomial.Identities.56_0.o6IrpyrTENfZuiK
private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z aโœ b : R m n : โ„• instโœ : CommRing R x y : R e : โ„• a : R โŠข a * (x + y) ^ e = a * (x ^ e + โ†‘e * x ^ (e - 1) * y + โ†‘(powAddExpansion x y e) * y ^ 2)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val
congr
private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val
Mathlib.Data.Polynomial.Identities.56_0.o6IrpyrTENfZuiK
private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) }
Mathlib_Data_Polynomial_Identities
case e_a R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z aโœ b : R m n : โ„• instโœ : CommRing R x y : R e : โ„• a : R โŠข (x + y) ^ e = x ^ e + โ†‘e * x ^ (e - 1) * y + โ†‘(powAddExpansion x y e) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr
apply (powAddExpansion _ _ _).property
private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr
Mathlib.Data.Polynomial.Identities.56_0.o6IrpyrTENfZuiK
private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข eval (x + y) f = sum f fun e a => a * (x ^ e + โ†‘e * x ^ (e - 1) * y + โ†‘(Polynomial.polyBinomAux1 x y e a) * y ^ 2)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by
unfold eval
private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by
Mathlib.Data.Polynomial.Identities.62_0.o6IrpyrTENfZuiK
private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2)
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข evalโ‚‚ (RingHom.id R) (x + y) f = sum f fun e a => a * (x ^ e + โ†‘e * x ^ (e - 1) * y + โ†‘(Polynomial.polyBinomAux1 x y e a) * y ^ 2)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval;
rw [evalโ‚‚_eq_sum]
private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval;
Mathlib.Data.Polynomial.Identities.62_0.o6IrpyrTENfZuiK
private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2)
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (sum f fun e a => (RingHom.id R) a * (x + y) ^ e) = sum f fun e a => a * (x ^ e + โ†‘e * x ^ (e - 1) * y + โ†‘(Polynomial.polyBinomAux1 x y e a) * y ^ 2)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum];
congr with (n z)
private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum];
Mathlib.Data.Polynomial.Identities.62_0.o6IrpyrTENfZuiK
private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2)
Mathlib_Data_Polynomial_Identities
case e_f.h.h R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m nโœ : โ„• instโœ : CommRing R f : R[X] x y : R n : โ„• z : R โŠข (RingHom.id R) z * (x + y) ^ n = z * (x ^ n + โ†‘n * x ^ (n - 1) * y + โ†‘(Polynomial.polyBinomAux1 x y n z) * y ^ 2)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z)
apply (polyBinomAux1 x y _ _).property
private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z)
Mathlib.Data.Polynomial.Identities.62_0.o6IrpyrTENfZuiK
private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2)
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข eval (x + y) f = ((sum f fun e a => a * x ^ e) + sum f fun e a => a * โ†‘e * x ^ (e - 1) * y) + sum f fun e a => a * โ†‘(Polynomial.polyBinomAux1 x y e a) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by
rw [poly_binom_aux2]
private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by
Mathlib.Data.Polynomial.Identities.68_0.o6IrpyrTENfZuiK
private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (sum f fun e a => a * (x ^ e + โ†‘e * x ^ (e - 1) * y + โ†‘(Polynomial.polyBinomAux1 x y e a) * y ^ 2)) = ((sum f fun e a => a * x ^ e) + sum f fun e a => a * โ†‘e * x ^ (e - 1) * y) + sum f fun e a => a * โ†‘(Polynomial.polyBinomAux1 x y e a) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2]
simp [left_distrib, sum_add, mul_assoc]
private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2]
Mathlib.Data.Polynomial.Identities.68_0.o6IrpyrTENfZuiK
private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข { k // eval (x + y) f = eval x f + eval x (derivative f) * y + k * y ^ 2 }
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by
exists f.sum fun e a => a * (polyBinomAux1 x y e a).val
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by
Mathlib.Data.Polynomial.Identities.75_0.o6IrpyrTENfZuiK
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข eval (x + y) f = eval x f + eval x (derivative f) * y + (sum f fun e a => a * โ†‘(Polynomial.polyBinomAux1 x y e a)) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val
rw [poly_binom_aux3]
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val
Mathlib.Data.Polynomial.Identities.75_0.o6IrpyrTENfZuiK
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (((sum f fun e a => a * x ^ e) + sum f fun e a => a * โ†‘e * x ^ (e - 1) * y) + sum f fun e a => a * โ†‘(Polynomial.polyBinomAux1 x y e a) * y ^ 2) = eval x f + eval x (derivative f) * y + (sum f fun e a => a * โ†‘(Polynomial.polyBinomAux1 x y e a)) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3]
congr
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3]
Mathlib.Data.Polynomial.Identities.75_0.o6IrpyrTENfZuiK
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 }
Mathlib_Data_Polynomial_Identities
case e_a.e_a R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (sum f fun e a => a * x ^ e) = eval x f
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท
rw [โ† eval_eq_sum]
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท
Mathlib.Data.Polynomial.Identities.75_0.o6IrpyrTENfZuiK
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 }
Mathlib_Data_Polynomial_Identities
case e_a.e_a R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (sum f fun e a => a * โ†‘e * x ^ (e - 1) * y) = eval x (derivative f) * y
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท
rw [derivative_eval]
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท
Mathlib.Data.Polynomial.Identities.75_0.o6IrpyrTENfZuiK
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 }
Mathlib_Data_Polynomial_Identities
case e_a.e_a R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (sum f fun e a => a * โ†‘e * x ^ (e - 1) * y) = (sum f fun n a => a * โ†‘n * x ^ (n - 1)) * y
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval]
exact Finset.sum_mul.symm
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval]
Mathlib.Data.Polynomial.Identities.75_0.o6IrpyrTENfZuiK
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 }
Mathlib_Data_Polynomial_Identities
case e_a R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (sum f fun e a => a * โ†‘(Polynomial.polyBinomAux1 x y e a) * y ^ 2) = (sum f fun e a => a * โ†‘(Polynomial.polyBinomAux1 x y e a)) * y ^ 2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท
exact Finset.sum_mul.symm
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท
Mathlib.Data.Polynomial.Identities.75_0.o6IrpyrTENfZuiK
/-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R x y : R โŠข x ^ 0 - y ^ 0 = 0 * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by
simp
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by
Mathlib.Data.Polynomial.Identities.90_0.o6IrpyrTENfZuiK
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R x y : R โŠข x ^ 1 - y ^ 1 = 1 * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by
simp
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by
Mathlib.Data.Polynomial.Identities.90_0.o6IrpyrTENfZuiK
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x kโœ : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R x y : R k : โ„• โŠข { z // x ^ (k + 2) - y ^ (k + 2) = z * (x - y) }
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by
cases' @powSubPowFactor x y (k + 1) with z hz
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by
Mathlib.Data.Polynomial.Identities.90_0.o6IrpyrTENfZuiK
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm
Mathlib_Data_Polynomial_Identities
case mk R : Type u S : Type v T : Type w ฮน : Type x kโœ : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R x y : R k : โ„• z : R hz : x ^ (k + 1) - y ^ (k + 1) = z * (x - y) โŠข { z // x ^ (k + 2) - y ^ (k + 2) = z * (x - y) }
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz
exists z * x + y ^ (k + 1)
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz
Mathlib.Data.Polynomial.Identities.90_0.o6IrpyrTENfZuiK
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm
Mathlib_Data_Polynomial_Identities
case mk R : Type u S : Type v T : Type w ฮน : Type x kโœ : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R x y : R k : โ„• z : R hz : x ^ (k + 1) - y ^ (k + 1) = z * (x - y) โŠข x ^ (k + 2) - y ^ (k + 2) = (z * x + y ^ (k + 1)) * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1)
linear_combination (norm := ring) x * hz
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1)
Mathlib.Data.Polynomial.Identities.90_0.o6IrpyrTENfZuiK
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm
Mathlib_Data_Polynomial_Identities
case a R : Type u S : Type v T : Type w ฮน : Type x kโœ : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R x y : R k : โ„• z : R hz : x ^ (k + 1) - y ^ (k + 1) = z * (x - y) โŠข x ^ (k + 2) - y ^ (k + 2) - (z * x + y ^ (k + 1)) * (x - y) - (x * (x ^ (k + 1) - y ^ (k + 1)) - x * (z * (x - y))) = 0
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm :=
ring
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm :=
Mathlib.Data.Polynomial.Identities.90_0.o6IrpyrTENfZuiK
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข { z // eval x f - eval y f = z * (x - y) }
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm := ring) x * hz #align polynomial.pow_sub_pow_factor Polynomial.powSubPowFactor /-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by
refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by
Mathlib.Data.Polynomial.Identities.101_0.o6IrpyrTENfZuiK
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข eval x f - eval y f = (sum f fun i r => r * โ†‘(powSubPowFactor x y i)) * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm := ring) x * hz #align polynomial.pow_sub_pow_factor Polynomial.powSubPowFactor /-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ
delta eval
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ
Mathlib.Data.Polynomial.Identities.101_0.o6IrpyrTENfZuiK
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข evalโ‚‚ (RingHom.id R) x f - evalโ‚‚ (RingHom.id R) y f = (sum f fun i r => r * โ†‘(powSubPowFactor x y i)) * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm := ring) x * hz #align polynomial.pow_sub_pow_factor Polynomial.powSubPowFactor /-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval;
rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum]
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval;
Mathlib.Data.Polynomial.Identities.101_0.o6IrpyrTENfZuiK
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข ((sum f fun e a => (RingHom.id R) a * x ^ e) - sum f fun e a => (RingHom.id R) a * y ^ e) = (sum f fun i r => r * โ†‘(powSubPowFactor x y i)) * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm := ring) x * hz #align polynomial.pow_sub_pow_factor Polynomial.powSubPowFactor /-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval; rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum];
simp only [sum, โ† Finset.sum_sub_distrib, Finset.sum_mul]
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval; rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum];
Mathlib.Data.Polynomial.Identities.101_0.o6IrpyrTENfZuiK
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (Finset.sum (support f) fun x_1 => (RingHom.id R) (coeff f x_1) * x ^ x_1 - (RingHom.id R) (coeff f x_1) * y ^ x_1) = Finset.sum (support f) fun x_1 => coeff f x_1 * โ†‘(powSubPowFactor x y x_1) * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm := ring) x * hz #align polynomial.pow_sub_pow_factor Polynomial.powSubPowFactor /-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval; rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum]; simp only [sum, โ† Finset.sum_sub_distrib, Finset.sum_mul]
dsimp
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval; rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum]; simp only [sum, โ† Finset.sum_sub_distrib, Finset.sum_mul]
Mathlib.Data.Polynomial.Identities.101_0.o6IrpyrTENfZuiK
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) }
Mathlib_Data_Polynomial_Identities
R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R โŠข (Finset.sum (support f) fun x_1 => coeff f x_1 * x ^ x_1 - coeff f x_1 * y ^ x_1) = Finset.sum (support f) fun x_1 => coeff f x_1 * โ†‘(powSubPowFactor x y x_1) * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm := ring) x * hz #align polynomial.pow_sub_pow_factor Polynomial.powSubPowFactor /-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval; rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum]; simp only [sum, โ† Finset.sum_sub_distrib, Finset.sum_mul] dsimp
congr with i
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval; rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum]; simp only [sum, โ† Finset.sum_sub_distrib, Finset.sum_mul] dsimp
Mathlib.Data.Polynomial.Identities.101_0.o6IrpyrTENfZuiK
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) }
Mathlib_Data_Polynomial_Identities
case e_f.h R : Type u S : Type v T : Type w ฮน : Type x k : Type y A : Type z a b : R m n : โ„• instโœ : CommRing R f : R[X] x y : R i : โ„• โŠข coeff f i * x ^ i - coeff f i * y ^ i = coeff f i * โ†‘(powSubPowFactor x y i) * (x - y)
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hรถlzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Data.Polynomial.Derivative import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Ring #align_import data.polynomial.identities from "leanprover-community/mathlib"@"4e1eeebe63ac6d44585297e89c6e7ee5cbda487a" /-! # Theory of univariate polynomials The main def is `Polynomial.binomExpansion`. -/ noncomputable section namespace Polynomial open Polynomial universe u v w x y z variable {R : Type u} {S : Type v} {T : Type w} {ฮน : Type x} {k : Type y} {A : Type z} {a b : R} {m n : โ„•} section Identities /- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials. These belong somewhere else. But not in group_power because they depend on tactic.ring_exp Maybe use `Data.Nat.Choose` to prove it. -/ /-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring. -/ def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) : โˆ€ n : โ„•, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ0, by simpโŸฉ | n + 2 => by cases' (powAddExpansion x y (n + 1)) with z hz exists x * z + (n + 1) * x ^ n + z * y calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring _ = (x + y) * (x ^ (n + 1) + โ†‘(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz] _ = x ^ (n + 2) + โ†‘(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by push_cast ring! #align polynomial.pow_add_expansion Polynomial.powAddExpansion variable [CommRing R] private def polyBinomAux1 (x y : R) (e : โ„•) (a : R) : { k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by exists (powAddExpansion x y e).val congr apply (powAddExpansion _ _ _).property private theorem poly_binom_aux2 (f : R[X]) (x y : R) : f.eval (x + y) = f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by unfold eval; rw [evalโ‚‚_eq_sum]; congr with (n z) apply (polyBinomAux1 x y _ _).property private theorem poly_binom_aux3 (f : R[X]) (x y : R) : f.eval (x + y) = ((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) + f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by rw [poly_binom_aux2] simp [left_distrib, sum_add, mul_assoc] /-- A polynomial `f` evaluated at `x + y` can be expressed as the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`, plus some element `k : R` times `y^2`. -/ def binomExpansion (f : R[X]) (x y : R) : { k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by exists f.sum fun e a => a * (polyBinomAux1 x y e a).val rw [poly_binom_aux3] congr ยท rw [โ† eval_eq_sum] ยท rw [derivative_eval] exact Finset.sum_mul.symm ยท exact Finset.sum_mul.symm #align polynomial.binom_expansion Polynomial.binomExpansion /-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def powSubPowFactor (x y : R) : โˆ€ i : โ„•, { z : R // x ^ i - y ^ i = z * (x - y) } | 0 => โŸจ0, by simpโŸฉ | 1 => โŸจ1, by simpโŸฉ | k + 2 => by cases' @powSubPowFactor x y (k + 1) with z hz exists z * x + y ^ (k + 1) linear_combination (norm := ring) x * hz #align polynomial.pow_sub_pow_factor Polynomial.powSubPowFactor /-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval; rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum]; simp only [sum, โ† Finset.sum_sub_distrib, Finset.sum_mul] dsimp congr with i
rw [mul_assoc, โ† (powSubPowFactor x y _).prop, mul_sub]
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by refine' โŸจf.sum fun i r => r * (powSubPowFactor x y i).val, _โŸฉ delta eval; rw [evalโ‚‚_eq_sum, evalโ‚‚_eq_sum]; simp only [sum, โ† Finset.sum_sub_distrib, Finset.sum_mul] dsimp congr with i
Mathlib.Data.Polynomial.Identities.101_0.o6IrpyrTENfZuiK
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)` for some `z` in the ring. -/ def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) }
Mathlib_Data_Polynomial_Identities
ฮน : Type u_1 ฮฑ : Type u_2 M : Type u_3 N : Type u_4 X : Type u_5 instโœยณ : TopologicalSpace X instโœยฒ : TopologicalSpace M instโœยน : Mul M instโœ : ContinuousMul M a b : M โŠข ๐“ a * ๐“ b โ‰ค ๐“ (a * b)
/- Copyright (c) 2017 Johannes Hรถlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hรถlzl, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Order.Filter.Pointwise import Mathlib.Topology.Algebra.MulAction import Mathlib.Algebra.BigOperators.Pi import Mathlib.Topology.ContinuousFunction.Basic #align_import topology.algebra.monoid from "leanprover-community/mathlib"@"1ac8d4304efba9d03fa720d06516fac845aa5353" /-! # Theory of topological monoids In this file we define mixin classes `ContinuousMul` and `ContinuousAdd`. While in many applications the underlying type is a monoid (multiplicative or additive), we do not require this in the definitions. -/ universe u v open Classical Set Filter TopologicalSpace open Classical Topology BigOperators Pointwise variable {ฮน ฮฑ M N X : Type*} [TopologicalSpace X] @[to_additive (attr := continuity)] theorem continuous_one [TopologicalSpace M] [One M] : Continuous (1 : X โ†’ M) := @continuous_const _ _ _ _ 1 #align continuous_one continuous_one #align continuous_zero continuous_zero /-- Basic hypothesis to talk about a topological additive monoid or a topological additive semigroup. A topological additive monoid over `M`, for example, is obtained by requiring both the instances `AddMonoid M` and `ContinuousAdd M`. Continuity in only the left/right argument can be stated using `ContinuousConstVAdd ฮฑ ฮฑ`/`ContinuousConstVAdd ฮฑแตแต’แต– ฮฑ`. -/ class ContinuousAdd (M : Type u) [TopologicalSpace M] [Add M] : Prop where continuous_add : Continuous fun p : M ร— M => p.1 + p.2 #align has_continuous_add ContinuousAdd /-- Basic hypothesis to talk about a topological monoid or a topological semigroup. A topological monoid over `M`, for example, is obtained by requiring both the instances `Monoid M` and `ContinuousMul M`. Continuity in only the left/right argument can be stated using `ContinuousConstSMul ฮฑ ฮฑ`/`ContinuousConstSMul ฮฑแตแต’แต– ฮฑ`. -/ @[to_additive] class ContinuousMul (M : Type u) [TopologicalSpace M] [Mul M] : Prop where continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 #align has_continuous_mul ContinuousMul section ContinuousMul variable [TopologicalSpace M] [Mul M] [ContinuousMul M] @[to_additive] instance : ContinuousMul Mแต’แตˆ := โ€นContinuousMul Mโ€บ @[to_additive (attr := continuity)] theorem continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 := ContinuousMul.continuous_mul #align continuous_mul continuous_mul #align continuous_add continuous_add @[to_additive] instance ContinuousMul.to_continuousSMul : ContinuousSMul M M := โŸจcontinuous_mulโŸฉ #align has_continuous_mul.to_has_continuous_smul ContinuousMul.to_continuousSMul #align has_continuous_add.to_has_continuous_vadd ContinuousAdd.to_continuousVAdd @[to_additive] instance ContinuousMul.to_continuousSMul_op : ContinuousSMul Mแตแต’แต– M := โŸจshow Continuous ((fun p : M ร— M => p.1 * p.2) โˆ˜ Prod.swap โˆ˜ Prod.map MulOpposite.unop id) from continuous_mul.comp <| continuous_swap.comp <| Continuous.prod_map MulOpposite.continuous_unop continuous_idโŸฉ #align has_continuous_mul.to_has_continuous_smul_op ContinuousMul.to_continuousSMul_op #align has_continuous_add.to_has_continuous_vadd_op ContinuousAdd.to_continuousVAdd_op @[to_additive (attr := continuity)] theorem Continuous.mul {f g : X โ†’ M} (hf : Continuous f) (hg : Continuous g) : Continuous fun x => f x * g x := continuous_mul.comp (hf.prod_mk hg : _) #align continuous.mul Continuous.mul #align continuous.add Continuous.add @[to_additive (attr := continuity)] theorem continuous_mul_left (a : M) : Continuous fun b : M => a * b := continuous_const.mul continuous_id #align continuous_mul_left continuous_mul_left #align continuous_add_left continuous_add_left @[to_additive (attr := continuity)] theorem continuous_mul_right (a : M) : Continuous fun b : M => b * a := continuous_id.mul continuous_const #align continuous_mul_right continuous_mul_right #align continuous_add_right continuous_add_right @[to_additive] theorem ContinuousOn.mul {f g : X โ†’ M} {s : Set X} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => f x * g x) s := (continuous_mul.comp_continuousOn (hf.prod hg) : _) #align continuous_on.mul ContinuousOn.mul #align continuous_on.add ContinuousOn.add @[to_additive] theorem tendsto_mul {a b : M} : Tendsto (fun p : M ร— M => p.fst * p.snd) (๐“ (a, b)) (๐“ (a * b)) := continuous_iff_continuousAt.mp ContinuousMul.continuous_mul (a, b) #align tendsto_mul tendsto_mul #align tendsto_add tendsto_add @[to_additive] theorem Filter.Tendsto.mul {f g : ฮฑ โ†’ M} {x : Filter ฮฑ} {a b : M} (hf : Tendsto f x (๐“ a)) (hg : Tendsto g x (๐“ b)) : Tendsto (fun x => f x * g x) x (๐“ (a * b)) := tendsto_mul.comp (hf.prod_mk_nhds hg) #align filter.tendsto.mul Filter.Tendsto.mul #align filter.tendsto.add Filter.Tendsto.add @[to_additive] theorem Filter.Tendsto.const_mul (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => b * f k) l (๐“ (b * c)) := tendsto_const_nhds.mul h #align filter.tendsto.const_mul Filter.Tendsto.const_mul #align filter.tendsto.const_add Filter.Tendsto.const_add @[to_additive] theorem Filter.Tendsto.mul_const (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => f k * b) l (๐“ (c * b)) := h.mul tendsto_const_nhds #align filter.tendsto.mul_const Filter.Tendsto.mul_const #align filter.tendsto.add_const Filter.Tendsto.add_const @[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b) := by
rw [โ† mapโ‚‚_mul, โ† map_uncurry_prod, โ† nhds_prod_eq]
@[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b) := by
Mathlib.Topology.Algebra.Monoid.139_0.3p9EZf9ZWFxWOAq
@[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b)
Mathlib_Topology_Algebra_Monoid
ฮน : Type u_1 ฮฑ : Type u_2 M : Type u_3 N : Type u_4 X : Type u_5 instโœยณ : TopologicalSpace X instโœยฒ : TopologicalSpace M instโœยน : Mul M instโœ : ContinuousMul M a b : M โŠข map (Function.uncurry fun x x_1 => x * x_1) (๐“ (a, b)) โ‰ค ๐“ (a * b)
/- Copyright (c) 2017 Johannes Hรถlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hรถlzl, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Order.Filter.Pointwise import Mathlib.Topology.Algebra.MulAction import Mathlib.Algebra.BigOperators.Pi import Mathlib.Topology.ContinuousFunction.Basic #align_import topology.algebra.monoid from "leanprover-community/mathlib"@"1ac8d4304efba9d03fa720d06516fac845aa5353" /-! # Theory of topological monoids In this file we define mixin classes `ContinuousMul` and `ContinuousAdd`. While in many applications the underlying type is a monoid (multiplicative or additive), we do not require this in the definitions. -/ universe u v open Classical Set Filter TopologicalSpace open Classical Topology BigOperators Pointwise variable {ฮน ฮฑ M N X : Type*} [TopologicalSpace X] @[to_additive (attr := continuity)] theorem continuous_one [TopologicalSpace M] [One M] : Continuous (1 : X โ†’ M) := @continuous_const _ _ _ _ 1 #align continuous_one continuous_one #align continuous_zero continuous_zero /-- Basic hypothesis to talk about a topological additive monoid or a topological additive semigroup. A topological additive monoid over `M`, for example, is obtained by requiring both the instances `AddMonoid M` and `ContinuousAdd M`. Continuity in only the left/right argument can be stated using `ContinuousConstVAdd ฮฑ ฮฑ`/`ContinuousConstVAdd ฮฑแตแต’แต– ฮฑ`. -/ class ContinuousAdd (M : Type u) [TopologicalSpace M] [Add M] : Prop where continuous_add : Continuous fun p : M ร— M => p.1 + p.2 #align has_continuous_add ContinuousAdd /-- Basic hypothesis to talk about a topological monoid or a topological semigroup. A topological monoid over `M`, for example, is obtained by requiring both the instances `Monoid M` and `ContinuousMul M`. Continuity in only the left/right argument can be stated using `ContinuousConstSMul ฮฑ ฮฑ`/`ContinuousConstSMul ฮฑแตแต’แต– ฮฑ`. -/ @[to_additive] class ContinuousMul (M : Type u) [TopologicalSpace M] [Mul M] : Prop where continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 #align has_continuous_mul ContinuousMul section ContinuousMul variable [TopologicalSpace M] [Mul M] [ContinuousMul M] @[to_additive] instance : ContinuousMul Mแต’แตˆ := โ€นContinuousMul Mโ€บ @[to_additive (attr := continuity)] theorem continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 := ContinuousMul.continuous_mul #align continuous_mul continuous_mul #align continuous_add continuous_add @[to_additive] instance ContinuousMul.to_continuousSMul : ContinuousSMul M M := โŸจcontinuous_mulโŸฉ #align has_continuous_mul.to_has_continuous_smul ContinuousMul.to_continuousSMul #align has_continuous_add.to_has_continuous_vadd ContinuousAdd.to_continuousVAdd @[to_additive] instance ContinuousMul.to_continuousSMul_op : ContinuousSMul Mแตแต’แต– M := โŸจshow Continuous ((fun p : M ร— M => p.1 * p.2) โˆ˜ Prod.swap โˆ˜ Prod.map MulOpposite.unop id) from continuous_mul.comp <| continuous_swap.comp <| Continuous.prod_map MulOpposite.continuous_unop continuous_idโŸฉ #align has_continuous_mul.to_has_continuous_smul_op ContinuousMul.to_continuousSMul_op #align has_continuous_add.to_has_continuous_vadd_op ContinuousAdd.to_continuousVAdd_op @[to_additive (attr := continuity)] theorem Continuous.mul {f g : X โ†’ M} (hf : Continuous f) (hg : Continuous g) : Continuous fun x => f x * g x := continuous_mul.comp (hf.prod_mk hg : _) #align continuous.mul Continuous.mul #align continuous.add Continuous.add @[to_additive (attr := continuity)] theorem continuous_mul_left (a : M) : Continuous fun b : M => a * b := continuous_const.mul continuous_id #align continuous_mul_left continuous_mul_left #align continuous_add_left continuous_add_left @[to_additive (attr := continuity)] theorem continuous_mul_right (a : M) : Continuous fun b : M => b * a := continuous_id.mul continuous_const #align continuous_mul_right continuous_mul_right #align continuous_add_right continuous_add_right @[to_additive] theorem ContinuousOn.mul {f g : X โ†’ M} {s : Set X} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => f x * g x) s := (continuous_mul.comp_continuousOn (hf.prod hg) : _) #align continuous_on.mul ContinuousOn.mul #align continuous_on.add ContinuousOn.add @[to_additive] theorem tendsto_mul {a b : M} : Tendsto (fun p : M ร— M => p.fst * p.snd) (๐“ (a, b)) (๐“ (a * b)) := continuous_iff_continuousAt.mp ContinuousMul.continuous_mul (a, b) #align tendsto_mul tendsto_mul #align tendsto_add tendsto_add @[to_additive] theorem Filter.Tendsto.mul {f g : ฮฑ โ†’ M} {x : Filter ฮฑ} {a b : M} (hf : Tendsto f x (๐“ a)) (hg : Tendsto g x (๐“ b)) : Tendsto (fun x => f x * g x) x (๐“ (a * b)) := tendsto_mul.comp (hf.prod_mk_nhds hg) #align filter.tendsto.mul Filter.Tendsto.mul #align filter.tendsto.add Filter.Tendsto.add @[to_additive] theorem Filter.Tendsto.const_mul (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => b * f k) l (๐“ (b * c)) := tendsto_const_nhds.mul h #align filter.tendsto.const_mul Filter.Tendsto.const_mul #align filter.tendsto.const_add Filter.Tendsto.const_add @[to_additive] theorem Filter.Tendsto.mul_const (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => f k * b) l (๐“ (c * b)) := h.mul tendsto_const_nhds #align filter.tendsto.mul_const Filter.Tendsto.mul_const #align filter.tendsto.add_const Filter.Tendsto.add_const @[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b) := by rw [โ† mapโ‚‚_mul, โ† map_uncurry_prod, โ† nhds_prod_eq]
exact continuous_mul.tendsto _
@[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b) := by rw [โ† mapโ‚‚_mul, โ† map_uncurry_prod, โ† nhds_prod_eq]
Mathlib.Topology.Algebra.Monoid.139_0.3p9EZf9ZWFxWOAq
@[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b)
Mathlib_Topology_Algebra_Monoid
ฮน : Type u_1 ฮฑ : Type u_2 M : Type u_3 N : Type u_4 X : Type u_5 instโœโธ : TopologicalSpace X instโœโท : TopologicalSpace M instโœโถ : Mul M instโœโต : ContinuousMul M instโœโด : TopologicalSpace N instโœยณ : Monoid N instโœยฒ : ContinuousMul N instโœยน : T2Space N f : ฮน โ†’ Nหฃ rโ‚ rโ‚‚ : N l : Filter ฮน instโœ : NeBot l hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚) hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚) โŠข rโ‚ * rโ‚‚ = 1
/- Copyright (c) 2017 Johannes Hรถlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hรถlzl, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Order.Filter.Pointwise import Mathlib.Topology.Algebra.MulAction import Mathlib.Algebra.BigOperators.Pi import Mathlib.Topology.ContinuousFunction.Basic #align_import topology.algebra.monoid from "leanprover-community/mathlib"@"1ac8d4304efba9d03fa720d06516fac845aa5353" /-! # Theory of topological monoids In this file we define mixin classes `ContinuousMul` and `ContinuousAdd`. While in many applications the underlying type is a monoid (multiplicative or additive), we do not require this in the definitions. -/ universe u v open Classical Set Filter TopologicalSpace open Classical Topology BigOperators Pointwise variable {ฮน ฮฑ M N X : Type*} [TopologicalSpace X] @[to_additive (attr := continuity)] theorem continuous_one [TopologicalSpace M] [One M] : Continuous (1 : X โ†’ M) := @continuous_const _ _ _ _ 1 #align continuous_one continuous_one #align continuous_zero continuous_zero /-- Basic hypothesis to talk about a topological additive monoid or a topological additive semigroup. A topological additive monoid over `M`, for example, is obtained by requiring both the instances `AddMonoid M` and `ContinuousAdd M`. Continuity in only the left/right argument can be stated using `ContinuousConstVAdd ฮฑ ฮฑ`/`ContinuousConstVAdd ฮฑแตแต’แต– ฮฑ`. -/ class ContinuousAdd (M : Type u) [TopologicalSpace M] [Add M] : Prop where continuous_add : Continuous fun p : M ร— M => p.1 + p.2 #align has_continuous_add ContinuousAdd /-- Basic hypothesis to talk about a topological monoid or a topological semigroup. A topological monoid over `M`, for example, is obtained by requiring both the instances `Monoid M` and `ContinuousMul M`. Continuity in only the left/right argument can be stated using `ContinuousConstSMul ฮฑ ฮฑ`/`ContinuousConstSMul ฮฑแตแต’แต– ฮฑ`. -/ @[to_additive] class ContinuousMul (M : Type u) [TopologicalSpace M] [Mul M] : Prop where continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 #align has_continuous_mul ContinuousMul section ContinuousMul variable [TopologicalSpace M] [Mul M] [ContinuousMul M] @[to_additive] instance : ContinuousMul Mแต’แตˆ := โ€นContinuousMul Mโ€บ @[to_additive (attr := continuity)] theorem continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 := ContinuousMul.continuous_mul #align continuous_mul continuous_mul #align continuous_add continuous_add @[to_additive] instance ContinuousMul.to_continuousSMul : ContinuousSMul M M := โŸจcontinuous_mulโŸฉ #align has_continuous_mul.to_has_continuous_smul ContinuousMul.to_continuousSMul #align has_continuous_add.to_has_continuous_vadd ContinuousAdd.to_continuousVAdd @[to_additive] instance ContinuousMul.to_continuousSMul_op : ContinuousSMul Mแตแต’แต– M := โŸจshow Continuous ((fun p : M ร— M => p.1 * p.2) โˆ˜ Prod.swap โˆ˜ Prod.map MulOpposite.unop id) from continuous_mul.comp <| continuous_swap.comp <| Continuous.prod_map MulOpposite.continuous_unop continuous_idโŸฉ #align has_continuous_mul.to_has_continuous_smul_op ContinuousMul.to_continuousSMul_op #align has_continuous_add.to_has_continuous_vadd_op ContinuousAdd.to_continuousVAdd_op @[to_additive (attr := continuity)] theorem Continuous.mul {f g : X โ†’ M} (hf : Continuous f) (hg : Continuous g) : Continuous fun x => f x * g x := continuous_mul.comp (hf.prod_mk hg : _) #align continuous.mul Continuous.mul #align continuous.add Continuous.add @[to_additive (attr := continuity)] theorem continuous_mul_left (a : M) : Continuous fun b : M => a * b := continuous_const.mul continuous_id #align continuous_mul_left continuous_mul_left #align continuous_add_left continuous_add_left @[to_additive (attr := continuity)] theorem continuous_mul_right (a : M) : Continuous fun b : M => b * a := continuous_id.mul continuous_const #align continuous_mul_right continuous_mul_right #align continuous_add_right continuous_add_right @[to_additive] theorem ContinuousOn.mul {f g : X โ†’ M} {s : Set X} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => f x * g x) s := (continuous_mul.comp_continuousOn (hf.prod hg) : _) #align continuous_on.mul ContinuousOn.mul #align continuous_on.add ContinuousOn.add @[to_additive] theorem tendsto_mul {a b : M} : Tendsto (fun p : M ร— M => p.fst * p.snd) (๐“ (a, b)) (๐“ (a * b)) := continuous_iff_continuousAt.mp ContinuousMul.continuous_mul (a, b) #align tendsto_mul tendsto_mul #align tendsto_add tendsto_add @[to_additive] theorem Filter.Tendsto.mul {f g : ฮฑ โ†’ M} {x : Filter ฮฑ} {a b : M} (hf : Tendsto f x (๐“ a)) (hg : Tendsto g x (๐“ b)) : Tendsto (fun x => f x * g x) x (๐“ (a * b)) := tendsto_mul.comp (hf.prod_mk_nhds hg) #align filter.tendsto.mul Filter.Tendsto.mul #align filter.tendsto.add Filter.Tendsto.add @[to_additive] theorem Filter.Tendsto.const_mul (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => b * f k) l (๐“ (b * c)) := tendsto_const_nhds.mul h #align filter.tendsto.const_mul Filter.Tendsto.const_mul #align filter.tendsto.const_add Filter.Tendsto.const_add @[to_additive] theorem Filter.Tendsto.mul_const (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => f k * b) l (๐“ (c * b)) := h.mul tendsto_const_nhds #align filter.tendsto.mul_const Filter.Tendsto.mul_const #align filter.tendsto.add_const Filter.Tendsto.add_const @[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b) := by rw [โ† mapโ‚‚_mul, โ† map_uncurry_prod, โ† nhds_prod_eq] exact continuous_mul.tendsto _ #align le_nhds_mul le_nhds_mul #align le_nhds_add le_nhds_add @[to_additive (attr := simp)] theorem nhds_one_mul_nhds {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : ๐“ (1 : M) * ๐“ a = ๐“ a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (one_mul a)).antisymm <| le_mul_of_one_le_left' <| pure_le_nhds 1 #align nhds_one_mul_nhds nhds_one_mul_nhds #align nhds_zero_add_nhds nhds_zero_add_nhds @[to_additive (attr := simp)] theorem nhds_mul_nhds_one {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : ๐“ a * ๐“ 1 = ๐“ a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (mul_one a)).antisymm <| le_mul_of_one_le_right' <| pure_le_nhds 1 #align nhds_mul_nhds_one nhds_mul_nhds_one #align nhds_add_nhds_zero nhds_add_nhds_zero section tendsto_nhds variable {๐•œ : Type*} [Preorder ๐•œ] [Zero ๐•œ] [Mul ๐•œ] [TopologicalSpace ๐•œ] [ContinuousMul ๐•œ] {l : Filter ฮฑ} {f : ฮฑ โ†’ ๐•œ} {b c : ๐•œ} (hb : 0 < b) theorem Filter.TendstoNhdsWithinIoi.const_mul [PosMulStrictMono ๐•œ] [PosMulReflectLT ๐•œ] (h : Tendsto f l (๐“[>] c)) : Tendsto (fun a => b * f a) l (๐“[>] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr #align filter.tendsto_nhds_within_Ioi.const_mul Filter.TendstoNhdsWithinIoi.const_mul theorem Filter.TendstoNhdsWithinIio.const_mul [PosMulStrictMono ๐•œ] [PosMulReflectLT ๐•œ] (h : Tendsto f l (๐“[<] c)) : Tendsto (fun a => b * f a) l (๐“[<] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr #align filter.tendsto_nhds_within_Iio.const_mul Filter.TendstoNhdsWithinIio.const_mul theorem Filter.TendstoNhdsWithinIoi.mul_const [MulPosStrictMono ๐•œ] [MulPosReflectLT ๐•œ] (h : Tendsto f l (๐“[>] c)) : Tendsto (fun a => f a * b) l (๐“[>] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr #align filter.tendsto_nhds_within_Ioi.mul_const Filter.TendstoNhdsWithinIoi.mul_const theorem Filter.TendstoNhdsWithinIio.mul_const [MulPosStrictMono ๐•œ] [MulPosReflectLT ๐•œ] (h : Tendsto f l (๐“[<] c)) : Tendsto (fun a => f a * b) l (๐“[<] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr #align filter.tendsto_nhds_within_Iio.mul_const Filter.TendstoNhdsWithinIio.mul_const end tendsto_nhds /-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr := simps) "Construct an additive unit from limits of additive units and their negatives."] def Filter.Tendsto.units [TopologicalSpace N] [Monoid N] [ContinuousMul N] [T2Space N] {f : ฮน โ†’ Nหฃ} {rโ‚ rโ‚‚ : N} {l : Filter ฮน} [l.NeBot] (hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚)) (hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚)) : Nหฃ where val := rโ‚ inv := rโ‚‚ val_inv := by
symm
/-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr := simps) "Construct an additive unit from limits of additive units and their negatives."] def Filter.Tendsto.units [TopologicalSpace N] [Monoid N] [ContinuousMul N] [T2Space N] {f : ฮน โ†’ Nหฃ} {rโ‚ rโ‚‚ : N} {l : Filter ฮน} [l.NeBot] (hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚)) (hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚)) : Nหฃ where val := rโ‚ inv := rโ‚‚ val_inv := by
Mathlib.Topology.Algebra.Monoid.197_0.3p9EZf9ZWFxWOAq
/-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr
Mathlib_Topology_Algebra_Monoid
ฮน : Type u_1 ฮฑ : Type u_2 M : Type u_3 N : Type u_4 X : Type u_5 instโœโธ : TopologicalSpace X instโœโท : TopologicalSpace M instโœโถ : Mul M instโœโต : ContinuousMul M instโœโด : TopologicalSpace N instโœยณ : Monoid N instโœยฒ : ContinuousMul N instโœยน : T2Space N f : ฮน โ†’ Nหฃ rโ‚ rโ‚‚ : N l : Filter ฮน instโœ : NeBot l hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚) hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚) โŠข 1 = rโ‚ * rโ‚‚
/- Copyright (c) 2017 Johannes Hรถlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hรถlzl, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Order.Filter.Pointwise import Mathlib.Topology.Algebra.MulAction import Mathlib.Algebra.BigOperators.Pi import Mathlib.Topology.ContinuousFunction.Basic #align_import topology.algebra.monoid from "leanprover-community/mathlib"@"1ac8d4304efba9d03fa720d06516fac845aa5353" /-! # Theory of topological monoids In this file we define mixin classes `ContinuousMul` and `ContinuousAdd`. While in many applications the underlying type is a monoid (multiplicative or additive), we do not require this in the definitions. -/ universe u v open Classical Set Filter TopologicalSpace open Classical Topology BigOperators Pointwise variable {ฮน ฮฑ M N X : Type*} [TopologicalSpace X] @[to_additive (attr := continuity)] theorem continuous_one [TopologicalSpace M] [One M] : Continuous (1 : X โ†’ M) := @continuous_const _ _ _ _ 1 #align continuous_one continuous_one #align continuous_zero continuous_zero /-- Basic hypothesis to talk about a topological additive monoid or a topological additive semigroup. A topological additive monoid over `M`, for example, is obtained by requiring both the instances `AddMonoid M` and `ContinuousAdd M`. Continuity in only the left/right argument can be stated using `ContinuousConstVAdd ฮฑ ฮฑ`/`ContinuousConstVAdd ฮฑแตแต’แต– ฮฑ`. -/ class ContinuousAdd (M : Type u) [TopologicalSpace M] [Add M] : Prop where continuous_add : Continuous fun p : M ร— M => p.1 + p.2 #align has_continuous_add ContinuousAdd /-- Basic hypothesis to talk about a topological monoid or a topological semigroup. A topological monoid over `M`, for example, is obtained by requiring both the instances `Monoid M` and `ContinuousMul M`. Continuity in only the left/right argument can be stated using `ContinuousConstSMul ฮฑ ฮฑ`/`ContinuousConstSMul ฮฑแตแต’แต– ฮฑ`. -/ @[to_additive] class ContinuousMul (M : Type u) [TopologicalSpace M] [Mul M] : Prop where continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 #align has_continuous_mul ContinuousMul section ContinuousMul variable [TopologicalSpace M] [Mul M] [ContinuousMul M] @[to_additive] instance : ContinuousMul Mแต’แตˆ := โ€นContinuousMul Mโ€บ @[to_additive (attr := continuity)] theorem continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 := ContinuousMul.continuous_mul #align continuous_mul continuous_mul #align continuous_add continuous_add @[to_additive] instance ContinuousMul.to_continuousSMul : ContinuousSMul M M := โŸจcontinuous_mulโŸฉ #align has_continuous_mul.to_has_continuous_smul ContinuousMul.to_continuousSMul #align has_continuous_add.to_has_continuous_vadd ContinuousAdd.to_continuousVAdd @[to_additive] instance ContinuousMul.to_continuousSMul_op : ContinuousSMul Mแตแต’แต– M := โŸจshow Continuous ((fun p : M ร— M => p.1 * p.2) โˆ˜ Prod.swap โˆ˜ Prod.map MulOpposite.unop id) from continuous_mul.comp <| continuous_swap.comp <| Continuous.prod_map MulOpposite.continuous_unop continuous_idโŸฉ #align has_continuous_mul.to_has_continuous_smul_op ContinuousMul.to_continuousSMul_op #align has_continuous_add.to_has_continuous_vadd_op ContinuousAdd.to_continuousVAdd_op @[to_additive (attr := continuity)] theorem Continuous.mul {f g : X โ†’ M} (hf : Continuous f) (hg : Continuous g) : Continuous fun x => f x * g x := continuous_mul.comp (hf.prod_mk hg : _) #align continuous.mul Continuous.mul #align continuous.add Continuous.add @[to_additive (attr := continuity)] theorem continuous_mul_left (a : M) : Continuous fun b : M => a * b := continuous_const.mul continuous_id #align continuous_mul_left continuous_mul_left #align continuous_add_left continuous_add_left @[to_additive (attr := continuity)] theorem continuous_mul_right (a : M) : Continuous fun b : M => b * a := continuous_id.mul continuous_const #align continuous_mul_right continuous_mul_right #align continuous_add_right continuous_add_right @[to_additive] theorem ContinuousOn.mul {f g : X โ†’ M} {s : Set X} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => f x * g x) s := (continuous_mul.comp_continuousOn (hf.prod hg) : _) #align continuous_on.mul ContinuousOn.mul #align continuous_on.add ContinuousOn.add @[to_additive] theorem tendsto_mul {a b : M} : Tendsto (fun p : M ร— M => p.fst * p.snd) (๐“ (a, b)) (๐“ (a * b)) := continuous_iff_continuousAt.mp ContinuousMul.continuous_mul (a, b) #align tendsto_mul tendsto_mul #align tendsto_add tendsto_add @[to_additive] theorem Filter.Tendsto.mul {f g : ฮฑ โ†’ M} {x : Filter ฮฑ} {a b : M} (hf : Tendsto f x (๐“ a)) (hg : Tendsto g x (๐“ b)) : Tendsto (fun x => f x * g x) x (๐“ (a * b)) := tendsto_mul.comp (hf.prod_mk_nhds hg) #align filter.tendsto.mul Filter.Tendsto.mul #align filter.tendsto.add Filter.Tendsto.add @[to_additive] theorem Filter.Tendsto.const_mul (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => b * f k) l (๐“ (b * c)) := tendsto_const_nhds.mul h #align filter.tendsto.const_mul Filter.Tendsto.const_mul #align filter.tendsto.const_add Filter.Tendsto.const_add @[to_additive] theorem Filter.Tendsto.mul_const (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => f k * b) l (๐“ (c * b)) := h.mul tendsto_const_nhds #align filter.tendsto.mul_const Filter.Tendsto.mul_const #align filter.tendsto.add_const Filter.Tendsto.add_const @[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b) := by rw [โ† mapโ‚‚_mul, โ† map_uncurry_prod, โ† nhds_prod_eq] exact continuous_mul.tendsto _ #align le_nhds_mul le_nhds_mul #align le_nhds_add le_nhds_add @[to_additive (attr := simp)] theorem nhds_one_mul_nhds {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : ๐“ (1 : M) * ๐“ a = ๐“ a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (one_mul a)).antisymm <| le_mul_of_one_le_left' <| pure_le_nhds 1 #align nhds_one_mul_nhds nhds_one_mul_nhds #align nhds_zero_add_nhds nhds_zero_add_nhds @[to_additive (attr := simp)] theorem nhds_mul_nhds_one {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : ๐“ a * ๐“ 1 = ๐“ a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (mul_one a)).antisymm <| le_mul_of_one_le_right' <| pure_le_nhds 1 #align nhds_mul_nhds_one nhds_mul_nhds_one #align nhds_add_nhds_zero nhds_add_nhds_zero section tendsto_nhds variable {๐•œ : Type*} [Preorder ๐•œ] [Zero ๐•œ] [Mul ๐•œ] [TopologicalSpace ๐•œ] [ContinuousMul ๐•œ] {l : Filter ฮฑ} {f : ฮฑ โ†’ ๐•œ} {b c : ๐•œ} (hb : 0 < b) theorem Filter.TendstoNhdsWithinIoi.const_mul [PosMulStrictMono ๐•œ] [PosMulReflectLT ๐•œ] (h : Tendsto f l (๐“[>] c)) : Tendsto (fun a => b * f a) l (๐“[>] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr #align filter.tendsto_nhds_within_Ioi.const_mul Filter.TendstoNhdsWithinIoi.const_mul theorem Filter.TendstoNhdsWithinIio.const_mul [PosMulStrictMono ๐•œ] [PosMulReflectLT ๐•œ] (h : Tendsto f l (๐“[<] c)) : Tendsto (fun a => b * f a) l (๐“[<] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr #align filter.tendsto_nhds_within_Iio.const_mul Filter.TendstoNhdsWithinIio.const_mul theorem Filter.TendstoNhdsWithinIoi.mul_const [MulPosStrictMono ๐•œ] [MulPosReflectLT ๐•œ] (h : Tendsto f l (๐“[>] c)) : Tendsto (fun a => f a * b) l (๐“[>] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr #align filter.tendsto_nhds_within_Ioi.mul_const Filter.TendstoNhdsWithinIoi.mul_const theorem Filter.TendstoNhdsWithinIio.mul_const [MulPosStrictMono ๐•œ] [MulPosReflectLT ๐•œ] (h : Tendsto f l (๐“[<] c)) : Tendsto (fun a => f a * b) l (๐“[<] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr #align filter.tendsto_nhds_within_Iio.mul_const Filter.TendstoNhdsWithinIio.mul_const end tendsto_nhds /-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr := simps) "Construct an additive unit from limits of additive units and their negatives."] def Filter.Tendsto.units [TopologicalSpace N] [Monoid N] [ContinuousMul N] [T2Space N] {f : ฮน โ†’ Nหฃ} {rโ‚ rโ‚‚ : N} {l : Filter ฮน} [l.NeBot] (hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚)) (hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚)) : Nหฃ where val := rโ‚ inv := rโ‚‚ val_inv := by symm
simpa using hโ‚.mul hโ‚‚
/-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr := simps) "Construct an additive unit from limits of additive units and their negatives."] def Filter.Tendsto.units [TopologicalSpace N] [Monoid N] [ContinuousMul N] [T2Space N] {f : ฮน โ†’ Nหฃ} {rโ‚ rโ‚‚ : N} {l : Filter ฮน} [l.NeBot] (hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚)) (hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚)) : Nหฃ where val := rโ‚ inv := rโ‚‚ val_inv := by symm
Mathlib.Topology.Algebra.Monoid.197_0.3p9EZf9ZWFxWOAq
/-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr
Mathlib_Topology_Algebra_Monoid
ฮน : Type u_1 ฮฑ : Type u_2 M : Type u_3 N : Type u_4 X : Type u_5 instโœโธ : TopologicalSpace X instโœโท : TopologicalSpace M instโœโถ : Mul M instโœโต : ContinuousMul M instโœโด : TopologicalSpace N instโœยณ : Monoid N instโœยฒ : ContinuousMul N instโœยน : T2Space N f : ฮน โ†’ Nหฃ rโ‚ rโ‚‚ : N l : Filter ฮน instโœ : NeBot l hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚) hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚) โŠข rโ‚‚ * rโ‚ = 1
/- Copyright (c) 2017 Johannes Hรถlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hรถlzl, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Order.Filter.Pointwise import Mathlib.Topology.Algebra.MulAction import Mathlib.Algebra.BigOperators.Pi import Mathlib.Topology.ContinuousFunction.Basic #align_import topology.algebra.monoid from "leanprover-community/mathlib"@"1ac8d4304efba9d03fa720d06516fac845aa5353" /-! # Theory of topological monoids In this file we define mixin classes `ContinuousMul` and `ContinuousAdd`. While in many applications the underlying type is a monoid (multiplicative or additive), we do not require this in the definitions. -/ universe u v open Classical Set Filter TopologicalSpace open Classical Topology BigOperators Pointwise variable {ฮน ฮฑ M N X : Type*} [TopologicalSpace X] @[to_additive (attr := continuity)] theorem continuous_one [TopologicalSpace M] [One M] : Continuous (1 : X โ†’ M) := @continuous_const _ _ _ _ 1 #align continuous_one continuous_one #align continuous_zero continuous_zero /-- Basic hypothesis to talk about a topological additive monoid or a topological additive semigroup. A topological additive monoid over `M`, for example, is obtained by requiring both the instances `AddMonoid M` and `ContinuousAdd M`. Continuity in only the left/right argument can be stated using `ContinuousConstVAdd ฮฑ ฮฑ`/`ContinuousConstVAdd ฮฑแตแต’แต– ฮฑ`. -/ class ContinuousAdd (M : Type u) [TopologicalSpace M] [Add M] : Prop where continuous_add : Continuous fun p : M ร— M => p.1 + p.2 #align has_continuous_add ContinuousAdd /-- Basic hypothesis to talk about a topological monoid or a topological semigroup. A topological monoid over `M`, for example, is obtained by requiring both the instances `Monoid M` and `ContinuousMul M`. Continuity in only the left/right argument can be stated using `ContinuousConstSMul ฮฑ ฮฑ`/`ContinuousConstSMul ฮฑแตแต’แต– ฮฑ`. -/ @[to_additive] class ContinuousMul (M : Type u) [TopologicalSpace M] [Mul M] : Prop where continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 #align has_continuous_mul ContinuousMul section ContinuousMul variable [TopologicalSpace M] [Mul M] [ContinuousMul M] @[to_additive] instance : ContinuousMul Mแต’แตˆ := โ€นContinuousMul Mโ€บ @[to_additive (attr := continuity)] theorem continuous_mul : Continuous fun p : M ร— M => p.1 * p.2 := ContinuousMul.continuous_mul #align continuous_mul continuous_mul #align continuous_add continuous_add @[to_additive] instance ContinuousMul.to_continuousSMul : ContinuousSMul M M := โŸจcontinuous_mulโŸฉ #align has_continuous_mul.to_has_continuous_smul ContinuousMul.to_continuousSMul #align has_continuous_add.to_has_continuous_vadd ContinuousAdd.to_continuousVAdd @[to_additive] instance ContinuousMul.to_continuousSMul_op : ContinuousSMul Mแตแต’แต– M := โŸจshow Continuous ((fun p : M ร— M => p.1 * p.2) โˆ˜ Prod.swap โˆ˜ Prod.map MulOpposite.unop id) from continuous_mul.comp <| continuous_swap.comp <| Continuous.prod_map MulOpposite.continuous_unop continuous_idโŸฉ #align has_continuous_mul.to_has_continuous_smul_op ContinuousMul.to_continuousSMul_op #align has_continuous_add.to_has_continuous_vadd_op ContinuousAdd.to_continuousVAdd_op @[to_additive (attr := continuity)] theorem Continuous.mul {f g : X โ†’ M} (hf : Continuous f) (hg : Continuous g) : Continuous fun x => f x * g x := continuous_mul.comp (hf.prod_mk hg : _) #align continuous.mul Continuous.mul #align continuous.add Continuous.add @[to_additive (attr := continuity)] theorem continuous_mul_left (a : M) : Continuous fun b : M => a * b := continuous_const.mul continuous_id #align continuous_mul_left continuous_mul_left #align continuous_add_left continuous_add_left @[to_additive (attr := continuity)] theorem continuous_mul_right (a : M) : Continuous fun b : M => b * a := continuous_id.mul continuous_const #align continuous_mul_right continuous_mul_right #align continuous_add_right continuous_add_right @[to_additive] theorem ContinuousOn.mul {f g : X โ†’ M} {s : Set X} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => f x * g x) s := (continuous_mul.comp_continuousOn (hf.prod hg) : _) #align continuous_on.mul ContinuousOn.mul #align continuous_on.add ContinuousOn.add @[to_additive] theorem tendsto_mul {a b : M} : Tendsto (fun p : M ร— M => p.fst * p.snd) (๐“ (a, b)) (๐“ (a * b)) := continuous_iff_continuousAt.mp ContinuousMul.continuous_mul (a, b) #align tendsto_mul tendsto_mul #align tendsto_add tendsto_add @[to_additive] theorem Filter.Tendsto.mul {f g : ฮฑ โ†’ M} {x : Filter ฮฑ} {a b : M} (hf : Tendsto f x (๐“ a)) (hg : Tendsto g x (๐“ b)) : Tendsto (fun x => f x * g x) x (๐“ (a * b)) := tendsto_mul.comp (hf.prod_mk_nhds hg) #align filter.tendsto.mul Filter.Tendsto.mul #align filter.tendsto.add Filter.Tendsto.add @[to_additive] theorem Filter.Tendsto.const_mul (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => b * f k) l (๐“ (b * c)) := tendsto_const_nhds.mul h #align filter.tendsto.const_mul Filter.Tendsto.const_mul #align filter.tendsto.const_add Filter.Tendsto.const_add @[to_additive] theorem Filter.Tendsto.mul_const (b : M) {c : M} {f : ฮฑ โ†’ M} {l : Filter ฮฑ} (h : Tendsto (fun k : ฮฑ => f k) l (๐“ c)) : Tendsto (fun k : ฮฑ => f k * b) l (๐“ (c * b)) := h.mul tendsto_const_nhds #align filter.tendsto.mul_const Filter.Tendsto.mul_const #align filter.tendsto.add_const Filter.Tendsto.add_const @[to_additive] theorem le_nhds_mul (a b : M) : ๐“ a * ๐“ b โ‰ค ๐“ (a * b) := by rw [โ† mapโ‚‚_mul, โ† map_uncurry_prod, โ† nhds_prod_eq] exact continuous_mul.tendsto _ #align le_nhds_mul le_nhds_mul #align le_nhds_add le_nhds_add @[to_additive (attr := simp)] theorem nhds_one_mul_nhds {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : ๐“ (1 : M) * ๐“ a = ๐“ a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (one_mul a)).antisymm <| le_mul_of_one_le_left' <| pure_le_nhds 1 #align nhds_one_mul_nhds nhds_one_mul_nhds #align nhds_zero_add_nhds nhds_zero_add_nhds @[to_additive (attr := simp)] theorem nhds_mul_nhds_one {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : ๐“ a * ๐“ 1 = ๐“ a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (mul_one a)).antisymm <| le_mul_of_one_le_right' <| pure_le_nhds 1 #align nhds_mul_nhds_one nhds_mul_nhds_one #align nhds_add_nhds_zero nhds_add_nhds_zero section tendsto_nhds variable {๐•œ : Type*} [Preorder ๐•œ] [Zero ๐•œ] [Mul ๐•œ] [TopologicalSpace ๐•œ] [ContinuousMul ๐•œ] {l : Filter ฮฑ} {f : ฮฑ โ†’ ๐•œ} {b c : ๐•œ} (hb : 0 < b) theorem Filter.TendstoNhdsWithinIoi.const_mul [PosMulStrictMono ๐•œ] [PosMulReflectLT ๐•œ] (h : Tendsto f l (๐“[>] c)) : Tendsto (fun a => b * f a) l (๐“[>] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr #align filter.tendsto_nhds_within_Ioi.const_mul Filter.TendstoNhdsWithinIoi.const_mul theorem Filter.TendstoNhdsWithinIio.const_mul [PosMulStrictMono ๐•œ] [PosMulReflectLT ๐•œ] (h : Tendsto f l (๐“[<] c)) : Tendsto (fun a => b * f a) l (๐“[<] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr #align filter.tendsto_nhds_within_Iio.const_mul Filter.TendstoNhdsWithinIio.const_mul theorem Filter.TendstoNhdsWithinIoi.mul_const [MulPosStrictMono ๐•œ] [MulPosReflectLT ๐•œ] (h : Tendsto f l (๐“[>] c)) : Tendsto (fun a => f a * b) l (๐“[>] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr #align filter.tendsto_nhds_within_Ioi.mul_const Filter.TendstoNhdsWithinIoi.mul_const theorem Filter.TendstoNhdsWithinIio.mul_const [MulPosStrictMono ๐•œ] [MulPosReflectLT ๐•œ] (h : Tendsto f l (๐“[<] c)) : Tendsto (fun a => f a * b) l (๐“[<] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr #align filter.tendsto_nhds_within_Iio.mul_const Filter.TendstoNhdsWithinIio.mul_const end tendsto_nhds /-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr := simps) "Construct an additive unit from limits of additive units and their negatives."] def Filter.Tendsto.units [TopologicalSpace N] [Monoid N] [ContinuousMul N] [T2Space N] {f : ฮน โ†’ Nหฃ} {rโ‚ rโ‚‚ : N} {l : Filter ฮน} [l.NeBot] (hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚)) (hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚)) : Nหฃ where val := rโ‚ inv := rโ‚‚ val_inv := by symm simpa using hโ‚.mul hโ‚‚ inv_val := by
symm
/-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr := simps) "Construct an additive unit from limits of additive units and their negatives."] def Filter.Tendsto.units [TopologicalSpace N] [Monoid N] [ContinuousMul N] [T2Space N] {f : ฮน โ†’ Nหฃ} {rโ‚ rโ‚‚ : N} {l : Filter ฮน} [l.NeBot] (hโ‚ : Tendsto (fun x => โ†‘(f x)) l (๐“ rโ‚)) (hโ‚‚ : Tendsto (fun x => โ†‘(f x)โปยน) l (๐“ rโ‚‚)) : Nหฃ where val := rโ‚ inv := rโ‚‚ val_inv := by symm simpa using hโ‚.mul hโ‚‚ inv_val := by
Mathlib.Topology.Algebra.Monoid.197_0.3p9EZf9ZWFxWOAq
/-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr
Mathlib_Topology_Algebra_Monoid