Skip to content

Commit 5d242aa

Browse files
fix: improve simp lemmas around PartENat.ofENat (#11553)
1 parent acda20c commit 5d242aa

File tree

2 files changed

+67
-70
lines changed

2 files changed

+67
-70
lines changed

Mathlib/Data/Nat/PartENat.lean

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -687,21 +687,43 @@ instance : Coe ℕ∞ PartENat := ⟨ofENat⟩
687687
example (n : ℕ) : ((n : ℕ∞) : PartENat) = ↑n := rfl
688688

689689
-- Porting note (#10756): new lemma
690-
@[simp]
691-
lemma ofENat_none : ofENat Option.none = ⊤ := rfl
690+
@[simp, norm_cast]
691+
lemma ofENat_top : ofENat = ⊤ := rfl
692692

693693
-- Porting note (#10756): new lemma
694-
@[simp]
695-
lemma ofENat_some (n : ℕ) : ofENat (Option.some n) = ↑n := rfl
694+
@[simp, norm_cast]
695+
lemma ofENat_coe (n : ℕ) : ofENat n = n := rfl
696+
697+
@[simp, norm_cast]
698+
theorem ofENat_zero : ofENat 0 = 0 := rfl
699+
700+
@[simp, norm_cast]
701+
theorem ofENat_one : ofENat 1 = 1 := rfl
702+
703+
@[simp, norm_cast]
704+
theorem ofENat_ofNat (n : Nat) [n.AtLeastTwo] : ofENat (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
705+
rfl
696706

697707
-- Porting note (#10756): new theorem
698708
@[simp, norm_cast]
699709
theorem toWithTop_ofENat (n : ℕ∞) {_ : Decidable (n : PartENat).Dom} : toWithTop (↑n) = n := by
700-
induction n with
701-
| none => simp; rfl
702-
| some n =>
703-
simp only [toWithTop_natCast', ofENat_some]
704-
rfl
710+
cases n using ENat.recTopCoe with
711+
| top => simp
712+
| coe n => simp
713+
714+
@[simp, norm_cast]
715+
theorem ofENat_toWithTop (x : PartENat) {_ : Decidable (x : PartENat).Dom} : toWithTop x = x := by
716+
induction x using PartENat.casesOn <;> simp
717+
718+
@[simp, norm_cast]
719+
theorem ofENat_le {x y : ℕ∞} : ofENat x ≤ ofENat y ↔ x ≤ y := by
720+
classical
721+
rw [← toWithTop_le, toWithTop_ofENat, toWithTop_ofENat]
722+
723+
@[simp, norm_cast]
724+
theorem ofENat_lt {x y : ℕ∞} : ofENat x < ofENat y ↔ x < y := by
725+
classical
726+
rw [← toWithTop_lt, toWithTop_ofENat, toWithTop_ofENat]
705727

706728
section WithTopEquiv
707729

@@ -717,98 +739,75 @@ theorem toWithTop_add {x y : PartENat} : toWithTop (x + y) = toWithTop x + toWit
717739
· simp_rw [toWithTop_natCast', ← Nat.cast_add, toWithTop_natCast', forall_const]
718740
#align part_enat.to_with_top_add PartENat.toWithTop_add
719741

720-
-- Porting note: The old proof of `right_inv` didn't work.
721-
-- (`by cases x; simp [with_top_equiv._match_1]; refl`)
722-
-- In order to get it to work, I introduced some new statements (see above),
723-
-- in particular `toWithTop_ofENat`.
724742
/-- `Equiv` between `PartENat` and `ℕ∞` (for the order isomorphism see
725743
`withTopOrderIso`). -/
744+
@[simps]
726745
noncomputable def withTopEquiv : PartENat ≃ ℕ∞ where
727746
toFun x := toWithTop x
728747
invFun x := ↑x
729-
left_inv x := by
730-
induction x using PartENat.casesOn <;>
731-
simp <;>
732-
rfl
733-
right_inv x := by
734-
simp [toWithTop_ofENat]
748+
left_inv x := by simp
749+
right_inv x := by simp
735750
#align part_enat.with_top_equiv PartENat.withTopEquiv
736751

737-
@[simp]
738-
theorem withTopEquiv_top : withTopEquiv ⊤ = ⊤ :=
739-
toWithTop_top'
752+
theorem withTopEquiv_top : withTopEquiv ⊤ = ⊤ := by
753+
simp
740754
#align part_enat.with_top_equiv_top PartENat.withTopEquiv_top
741755

742-
@[simp]
743-
theorem withTopEquiv_natCast (n : Nat) : withTopEquiv n = n :=
744-
toWithTop_natCast' _
756+
theorem withTopEquiv_natCast (n : Nat) : withTopEquiv n = n := by
757+
simp
745758
#align part_enat.with_top_equiv_coe PartENat.withTopEquiv_natCast
746759

747-
@[simp]
748760
theorem withTopEquiv_zero : withTopEquiv 0 = 0 := by
749-
simpa only [Nat.cast_zero] using withTopEquiv_natCast 0
761+
simp
750762
#align part_enat.with_top_equiv_zero PartENat.withTopEquiv_zero
751763

752-
@[simp]
753764
theorem withTopEquiv_one : withTopEquiv 1 = 1 := by
754-
simpa only [Nat.cast_one] using withTopEquiv_natCast 1
765+
simp
755766

756-
@[simp]
757767
theorem withTopEquiv_ofNat (n : Nat) [n.AtLeastTwo] :
758-
withTopEquiv (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
759-
withTopEquiv_natCast n
768+
withTopEquiv (no_index (OfNat.ofNat n)) = OfNat.ofNat n := by
769+
simp
760770

761-
@[simp]
762-
theorem withTopEquiv_le {x y : PartENat} : withTopEquiv x ≤ withTopEquiv y ↔ x ≤ y :=
763-
toWithTop_le
771+
theorem withTopEquiv_le {x y : PartENat} : withTopEquiv x ≤ withTopEquiv y ↔ x ≤ y := by
772+
simp
764773
#align part_enat.with_top_equiv_le PartENat.withTopEquiv_le
765774

766-
@[simp]
767-
theorem withTopEquiv_lt {x y : PartENat} : withTopEquiv x < withTopEquiv y ↔ x < y :=
768-
toWithTop_lt
775+
theorem withTopEquiv_lt {x y : PartENat} : withTopEquiv x < withTopEquiv y ↔ x < y := by
776+
simp
769777
#align part_enat.with_top_equiv_lt PartENat.withTopEquiv_lt
770778

771-
/-- `to_WithTop` induces an order isomorphism between `PartENat` and `ℕ∞`. -/
772-
noncomputable def withTopOrderIso : PartENat ≃o ℕ∞ :=
773-
{ withTopEquiv with map_rel_iff' := @fun _ _ => withTopEquiv_le }
774-
#align part_enat.with_top_order_iso PartENat.withTopOrderIso
775-
776-
@[simp]
777-
theorem withTopEquiv_symm_top : withTopEquiv.symm ⊤ = ⊤ :=
778-
rfl
779+
theorem withTopEquiv_symm_top : withTopEquiv.symm ⊤ = ⊤ := by
780+
simp
779781
#align part_enat.with_top_equiv_symm_top PartENat.withTopEquiv_symm_top
780782

781-
@[simp]
782-
theorem withTopEquiv_symm_coe (n : Nat) : withTopEquiv.symm n = n :=
783-
rfl
783+
theorem withTopEquiv_symm_coe (n : Nat) : withTopEquiv.symm n = n := by
784+
simp
784785
#align part_enat.with_top_equiv_symm_coe PartENat.withTopEquiv_symm_coe
785786

786-
@[simp]
787-
theorem withTopEquiv_symm_zero : withTopEquiv.symm 0 = 0 :=
788-
rfl
787+
theorem withTopEquiv_symm_zero : withTopEquiv.symm 0 = 0 := by
788+
simp
789789
#align part_enat.with_top_equiv_symm_zero PartENat.withTopEquiv_symm_zero
790790

791-
@[simp]
792-
theorem withTopEquiv_symm_one : withTopEquiv.symm 1 = 1 :=
793-
rfl
791+
theorem withTopEquiv_symm_one : withTopEquiv.symm 1 = 1 := by
792+
simp
794793

795-
@[simp]
796794
theorem withTopEquiv_symm_ofNat (n : Nat) [n.AtLeastTwo] :
797-
withTopEquiv.symm (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
798-
rfl
795+
withTopEquiv.symm (no_index (OfNat.ofNat n)) = OfNat.ofNat n := by
796+
simp
799797

800-
@[simp]
801798
theorem withTopEquiv_symm_le {x y : ℕ∞} : withTopEquiv.symm x ≤ withTopEquiv.symm y ↔ x ≤ y := by
802-
rw [← withTopEquiv_le]
803799
simp
804800
#align part_enat.with_top_equiv_symm_le PartENat.withTopEquiv_symm_le
805801

806-
@[simp]
807802
theorem withTopEquiv_symm_lt {x y : ℕ∞} : withTopEquiv.symm x < withTopEquiv.symm y ↔ x < y := by
808-
rw [← withTopEquiv_lt]
809803
simp
810804
#align part_enat.with_top_equiv_symm_lt PartENat.withTopEquiv_symm_lt
811805

806+
/-- `toWithTop` induces an order isomorphism between `PartENat` and `ℕ∞`. -/
807+
noncomputable def withTopOrderIso : PartENat ≃o ℕ∞ :=
808+
{ withTopEquiv with map_rel_iff' := @fun _ _ => withTopEquiv_le }
809+
#align part_enat.with_top_order_iso PartENat.withTopOrderIso
810+
812811
/-- `toWithTop` induces an additive monoid isomorphism between `PartENat` and `ℕ∞`. -/
813812
noncomputable def withTopAddEquiv : PartENat ≃+ ℕ∞ :=
814813
{ withTopEquiv with

Mathlib/SetTheory/Cardinal/PartENat.lean

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ theorem partENatOfENat_toENat (c : Cardinal) : (toENat c : PartENat) = toPartENa
3737

3838
@[simp]
3939
theorem toPartENat_natCast (n : ℕ) : toPartENat n = n := by
40-
simp only [← partENatOfENat_toENat, toENat_nat]; rfl
40+
simp only [← partENatOfENat_toENat, toENat_nat, PartENat.ofENat_coe]
4141
#align cardinal.to_part_enat_cast Cardinal.toPartENat_natCast
4242

4343
theorem toPartENat_apply_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : toPartENat c = toNat c := by
@@ -48,7 +48,7 @@ theorem toPartENat_eq_top {c : Cardinal} :
4848
toPartENat c = ⊤ ↔ ℵ₀ ≤ c := by
4949
rw [← partENatOfENat_toENat, ← PartENat.withTopEquiv_symm_top, ← toENat_eq_top,
5050
← PartENat.withTopEquiv.symm.injective.eq_iff]
51-
rfl
51+
simp
5252
#align to_part_enat_eq_top_iff_le_aleph_0 Cardinal.toPartENat_eq_top
5353

5454
theorem toPartENat_apply_of_aleph0_le {c : Cardinal} (h : ℵ₀ ≤ c) : toPartENat c = ⊤ :=
@@ -80,17 +80,15 @@ theorem toPartENat_strictMonoOn : StrictMonoOn toPartENat (Set.Iic ℵ₀) :=
8080
lemma toPartENat_le_iff_of_le_aleph0 {c c' : Cardinal} (h : c ≤ ℵ₀) :
8181
toPartENat c ≤ toPartENat c' ↔ c ≤ c' := by
8282
lift c to ℕ∞ using h
83-
simp only [← partENatOfENat_toENat, toENat_ofENat, enat_gc _,
84-
← PartENat.withTopOrderIso.symm.le_iff_le]
85-
rfl
83+
simp_rw [← partENatOfENat_toENat, toENat_ofENat, enat_gc _,
84+
← PartENat.withTopOrderIso.symm.le_iff_le, PartENat.ofENat_le, map_le_map_iff]
8685
#align to_part_enat_le_iff_le_of_le_aleph_0 Cardinal.toPartENat_le_iff_of_le_aleph0
8786

8887
lemma toPartENat_le_iff_of_lt_aleph0 {c c' : Cardinal} (hc' : c' < ℵ₀) :
8988
toPartENat c ≤ toPartENat c' ↔ c ≤ c' := by
9089
lift c' to ℕ using hc'
91-
simp only [← partENatOfENat_toENat, toENat_nat, ← toENat_le_nat,
92-
← PartENat.withTopOrderIso.symm.le_iff_le]
93-
rfl
90+
simp_rw [← partENatOfENat_toENat, toENat_nat, ← toENat_le_nat,
91+
← PartENat.withTopOrderIso.symm.le_iff_le, PartENat.ofENat_le, map_le_map_iff]
9492
#align to_part_enat_le_iff_le_of_lt_aleph_0 Cardinal.toPartENat_le_iff_of_lt_aleph0
9593

9694
lemma toPartENat_eq_iff_of_le_aleph0 {c c' : Cardinal} (hc : c ≤ ℵ₀) (hc' : c' ≤ ℵ₀) :

0 commit comments

Comments
 (0)