@@ -7638,7 +7638,7 @@ theorem beqModel_eq_true_of_perm [BEq α] [LawfulBEq α] [LawfulBEq α] [∀ k,
76387638 rw [beqModel, if_neg (by simpa using hyp.length_eq)]
76397639 simp only [List.all_eq_true]
76407640 intro ⟨k,v⟩ mem
7641- have hv := @ getValueCast_of_mem α β _ _ l₁ ⟨k,v⟩ mem
7641+ have hv := getValueCast_of_mem mem
76427642 have hc := containsKey_of_mem mem
76437643 apply beq_of_eq
76447644 simp only at |- hc hv
@@ -7662,90 +7662,56 @@ theorem Const.beqModel_eq_true_of_perm {β : Type v} [BEq α] [EquivBEq α] [BEq
76627662 · exact hl₁
76637663 · exact hc
76647664
7665- theorem perm_of_beqModel [BEq α] [LawfulBEq α] [∀ k, BEq (β k)] [∀ k, LawfulBEq (β k)] {l₁ l₂ : List ((a : α) × β a)} (hl₁ : DistinctKeys l₁) (hl₂ : DistinctKeys l₂) :
7666- beqModel l₁ l₂ → l₁.Perm l₂ := by
7667- rw [beqModel]
7668- split
7669- case isTrue => intro; contradiction
7670- case isFalse he =>
7671- simp only [ne_eq, Decidable.not_not] at he
7672- simp only [List.all_eq_true, beq_iff_eq]
7673- intro hyp
7674- apply getValueCast?_ext hl₁ hl₂
7675- intro a
7676- have hyp2 : ∀ (a : α) (h : containsKey a l₁), (getValueCast? a l₂ == getValueCast? a l₁) = true := by
7665+ theorem perm_of_beqModel [BEq α] [LawfulBEq α] [∀ k, BEq (β k)] [∀ k, LawfulBEq (β k)] {l₁ l₂ : List ((a : α) × β a)} (hl₁ : DistinctKeys l₁) (hl₂ : DistinctKeys l₂) : beqModel l₁ l₂ → l₁.Perm l₂ := by
7666+ simp only [beqModel, ne_eq, ite_not, Bool.if_false_right, Bool.and_eq_true, decide_eq_true_eq,
7667+ List.all_eq_true, beq_iff_eq, and_imp]
7668+ intro he hyp
7669+ apply getValueCast?_ext hl₁ hl₂
7670+ intro a
7671+ have hyp2 : ∀ (a : α) (h : containsKey a l₁), (getValueCast? a l₂ == getValueCast? a l₁) = true := by
76777672 intro a mem
76787673 rw [getValueCast?_eq_some_getValueCast mem]
76797674 apply beq_of_eq
7680- specialize hyp ⟨a, getValueCast a l₁ mem⟩
7681- specialize hyp (by apply List.getValueCast_mem)
7682- simp only at hyp
7683- rw [hyp]
7684- by_cases hc₁ : containsKey a l₁
7675+ specialize hyp ⟨a, getValueCast a l₁ mem⟩ (List.getValueCast_mem mem)
7676+ simpa using hyp
7677+ by_cases hc₁ : containsKey a l₁
7678+ case pos =>
7679+ exact eq_of_beq <| BEq.symm <| hyp2 _ hc₁
7680+ case neg =>
7681+ rw [Bool.not_eq_true] at hc₁
7682+ by_cases hc₂ : containsKey a l₂
76857683 case pos =>
7686- apply eq_of_beq
7687- apply BEq.symm
7688- apply hyp2
7689- exact hc₁
7684+ suffices (∀ (a : α), containsKey a l₁ = true → containsKey a l₂ = true) by
7685+ rw [containsKey_of_length_eq hl₁ hl₂ he.symm this a hc₂] at hc₁
7686+ contradiction
7687+ intro k' mem
7688+ apply List.containsKey_of_getValueCast?_eq_some
7689+ simpa [getValueCast?_eq_some_getValueCast mem] using eq_of_beq <| hyp2 k' mem
76907690 case neg =>
7691- rw [Bool.not_eq_true] at hc₁
7692- by_cases hc₂ : containsKey a l₂
7693- case pos =>
7694- suffices (∀ (a : α), containsKey a l₁ = true → containsKey a l₂ = true) by
7695- rw [@containsKey_of_length_eq α β _ _ l₁ l₂ hl₁ hl₂ he.symm this a hc₂] at hc₁
7696- contradiction
7697- intro k' mem
7698- have := eq_of_beq <| hyp2 k' mem
7699- rw [getValueCast?_eq_some_getValueCast mem] at this
7700- apply List.containsKey_of_getValueCast?_eq_some
7701- exact this
7702- case neg =>
7703- rw [Bool.not_eq_true] at hc₂
7704- rw [getValueCast?_eq_none hc₁, getValueCast?_eq_none hc₂]
7691+ rw [Bool.not_eq_true] at hc₂
7692+ rw [getValueCast?_eq_none hc₁, getValueCast?_eq_none hc₂]
77057693
77067694theorem beqModel_congr [BEq α] [LawfulBEq α] [∀ k, BEq (β k)] {l₁ l₂ l₃ l₄ : List ((a : α) × β a)}
77077695 (hl : DistinctKeys l₂) (p₁ : l₁.Perm l₃) (p₂ : l₂.Perm l₄) : beqModel l₁ l₂ = beqModel l₃ l₄ := by
7708- rw [beqModel]
7709- split
7710- case isTrue h =>
7711- rw [ne_eq] at h
7712- rw [beqModel]
7713- simp only [ne_eq, ite_not, Bool.if_false_right, Bool.false_eq, Bool.and_eq_false_imp,
7714- decide_eq_true_eq]
7715- intro hyp
7716- rw [Perm.length_eq p₁, Perm.length_eq p₂] at h
7717- contradiction
7718- case isFalse h =>
7719- rw [beqModel]
7720- rw [Perm.length_eq p₁, Perm.length_eq p₂] at h
7721- simp only [h, ↓reduceIte]
7722- have : fun (x : (a : α) × β a) => getValueCast? x.fst l₂ == some x.snd = fun x => getValueCast? x.fst l₄ == some x.snd := by
7723- ext x
7724- rw [getValueCast?_of_perm hl p₂]
7725- rw [this ]
7726- apply List.Perm.all_eq p₁
7696+ simp only [beqModel, ne_eq, ite_not, Bool.if_false_right, Perm.length_eq p₁, Perm.length_eq p₂]
7697+ suffices h : (l₁.all fun x => getValueCast? x.fst l₂ == some x.snd) = (l₃.all fun x => getValueCast? x.fst l₄ == some x.snd) by simp [h]
7698+ conv =>
7699+ lhs
7700+ rhs
7701+ ext x
7702+ rw [getValueCast?_of_perm hl p₂]
7703+ apply List.Perm.all_eq p₁
77277704
77287705theorem Const.beqModel_congr {β : Type v} [BEq α] [EquivBEq α] [BEq β] {l₁ l₂ l₃ l₄ : List ((_ : α) × β)}
77297706 (hl : DistinctKeys l₂) (p₁ : l₁.Perm l₃) (p₂ : l₂.Perm l₄) : beqModel l₁ l₂ = beqModel l₃ l₄ := by
7730- rw [beqModel]
7731- split
7732- case isTrue h =>
7733- rw [ne_eq] at h
7734- rw [beqModel]
7735- simp only [ne_eq, ite_not, Bool.if_false_right, Bool.false_eq, Bool.and_eq_false_imp,
7736- decide_eq_true_eq]
7737- intro hyp
7738- rw [Perm.length_eq p₁, Perm.length_eq p₂] at h
7739- contradiction
7740- case isFalse h =>
7741- rw [beqModel]
7742- rw [Perm.length_eq p₁, Perm.length_eq p₂] at h
7743- simp only [h, ↓reduceIte]
7744- have : fun (x : (_ : α) × β) => getValue? x.fst l₂ == some x.snd = fun x => getValue? x.fst l₄ == some x.snd := by
7745- ext x
7746- rw [getValue?_of_perm hl p₂]
7747- rw [this ]
7748- apply List.Perm.all_eq p₁
7707+ simp only [beqModel, ne_eq, ite_not, Bool.if_false_right, Perm.length_eq p₁, Perm.length_eq p₂]
7708+ suffices h : (l₁.all fun x => getValue? x.fst l₂ == some x.snd) = (l₃.all fun x => getValue? x.fst l₄ == some x.snd) by simp [h]
7709+ conv =>
7710+ lhs
7711+ rhs
7712+ ext x
7713+ rw [getValue?_of_perm hl p₂]
7714+ apply List.Perm.all_eq p₁
77497715
77507716theorem beqModel_eq_constBeqModel {β : Type v} [BEq α] [LawfulBEq α] [BEq β] {l₁ l₂ : List ((_ : α) × β)} : beqModel l₁ l₂ = Const.beqModel l₁ l₂ := by
77517717 rw [beqModel, Const.beqModel]
@@ -7757,10 +7723,7 @@ theorem Const.perm_of_beqModel {β : Type v} [BEq α] [LawfulBEq α] [BEq β] [L
77577723 beqModel l₁ l₂ → l₁.Perm l₂ := by
77587724 rw [← beqModel_eq_constBeqModel]
77597725 intro hyp
7760- apply List.perm_of_beqModel
7761- · exact hl₁
7762- · exact hl₂
7763- · exact hyp
7726+ apply List.perm_of_beqModel hl₁ hl₂ hyp
77647727
77657728namespace Const
77667729
0 commit comments