Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 879273e

Browse files
committed
feat(logic/basic, logic/function/basic): make cast the simp-normal form of eq.mp and eq.mpr, add lemmas (#6834)
This adds the fact that `eq.rec`, `eq.mp`, `eq.mpr`, and `cast` are bijective, as well as some simp lemmas that follow from their injectivity.
1 parent 81e8a13 commit 879273e

File tree

8 files changed

+45
-15
lines changed

8 files changed

+45
-15
lines changed

src/data/fin.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,15 +1282,15 @@ begin
12821282
{ have : update (snoc p x) j (_root_.cast C1 y) j = _root_.cast C1 y, by simp,
12831283
convert this,
12841284
{ exact h'.symm },
1285-
{ exact heq_of_eq_mp (congr_arg α (eq.symm h')) rfl } },
1285+
{ exact heq_of_cast_eq (congr_arg α (eq.symm h')) rfl } },
12861286
have C2 : α i.cast_succ = α (cast_succ (cast_lt j h)),
12871287
by rw [cast_succ_cast_lt, h'],
12881288
have E2 : update p i y (cast_lt j h) = _root_.cast C2 y,
12891289
{ have : update p (cast_lt j h) (_root_.cast C2 y) (cast_lt j h) = _root_.cast C2 y,
12901290
by simp,
12911291
convert this,
12921292
{ simp [h, h'] },
1293-
{ exact heq_of_eq_mp C2 rfl } },
1293+
{ exact heq_of_cast_eq C2 rfl } },
12941294
rw [E1, E2],
12951295
exact eq_rec_compose _ _ _ },
12961296
{ have : ¬(cast_lt j h = i),

src/data/padics/ring_homs.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ begin
267267
dsimp [to_zmod, to_zmod_hom],
268268
unfreezingI { rcases (exists_eq_add_of_lt (hp_prime.1.pos)) with ⟨p', rfl⟩ },
269269
change ↑(zmod.val _) = _,
270-
simp only [zmod.val_nat_cast, add_zero, add_def, cast_inj, zero_add],
270+
simp only [zmod.val_nat_cast, add_zero, add_def, nat.cast_inj, zero_add],
271271
apply mod_eq_of_lt,
272272
simpa only [zero_add] using zmod_repr_lt_p z,
273273
end

src/data/real/irrational.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ then iff_of_false (not_not_intro ⟨rat.sqrt q,
105105
sqrt_eq, abs_of_nonneg (rat.sqrt_nonneg q)]⟩) (λ h, h.1 H1)
106106
else if H2 : 0 ≤ q
107107
then iff_of_true (λ ⟨r, hr⟩, H1 $ (exists_mul_self _).1 ⟨r,
108-
by rwa [eq_comm, sqrt_eq_iff_mul_self_eq (cast_nonneg.2 H2), ← cast_mul, cast_inj] at hr;
108+
by rwa [eq_comm, sqrt_eq_iff_mul_self_eq (cast_nonneg.2 H2), ← cast_mul, rat.cast_inj] at hr;
109109
rw [← hr]; exact real.sqrt_nonneg _⟩) ⟨H1, H2⟩
110110
else iff_of_false (not_not_intro ⟨0,
111111
by rw cast_zero; exact (sqrt_eq_zero_of_nonpos (rat.cast_nonpos.2 $ le_of_not_le H2)).symm⟩)

src/logic/basic.lean

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ attribute [inline] and.decidable or.decidable decidable.false xor.decidable iff.
3030
decidable.true implies.decidable not.decidable ne.decidable
3131
bool.decidable_eq decidable.to_bool
3232

33-
attribute [simp] cast_eq
33+
attribute [simp] cast_eq cast_heq
3434

3535
variables {α : Type*} {β : Type*}
3636

@@ -655,10 +655,15 @@ lemma eq_rec_constant {α : Sort*} {a a' : α} {β : Sort*} (y : β) (h : a = a'
655655
by { cases h, refl, }
656656

657657
@[simp]
658-
lemma eq_mp_rfl {α : Sort*} {a : α} : eq.mp (eq.refl α) a = a := rfl
658+
lemma eq_mp_eq_castβ : Sort*} (h : α = β) : eq.mp h = cast h := rfl
659659

660660
@[simp]
661-
lemma eq_mpr_rfl {α : Sort*} {a : α} : eq.mpr (eq.refl α) a = a := rfl
661+
lemma eq_mpr_eq_cast {α β : Sort*} (h : α = β) : eq.mpr h = cast h.symm := rfl
662+
663+
@[simp]
664+
lemma cast_cast : ∀ {α β γ : Sort*} (ha : α = β) (hb : β = γ) (a : α),
665+
cast hb (cast ha a) = cast (ha.trans hb) a
666+
| _ _ _ rfl rfl a := rfl
662667

663668
@[simp] lemma congr_refl_left {α β : Sort*} (f : α → β) {a b : α} (h : a = b) :
664669
congr (eq.refl f) h = congr_arg f h :=
@@ -680,17 +685,14 @@ rfl
680685
congr_fun (congr_arg f p) b = congr_arg (λ a, f a b) p :=
681686
rfl
682687

683-
lemma heq_of_eq_mp :
684-
∀ {α β : Sort*} {a : α} {a' : β} (e : α = β) (h₂ : (eq.mp e a) = a'), a == a'
688+
lemma heq_of_cast_eq :
689+
∀ {α β : Sort*} {a : α} {a' : β} (e : α = β) (h₂ : cast e a = a'), a == a'
685690
| α ._ a a' rfl h := eq.rec_on h (heq.refl _)
686691

687692
lemma rec_heq_of_heq {β} {C : α → Sort*} {x : C a} {y : β} (eq : a = b) (h : x == y) :
688693
@eq.rec α a C x b eq == y :=
689694
by subst eq; exact h
690695

691-
@[simp] lemma {u} eq_mpr_heq {α β : Sort u} (h : β = α) (x : α) : eq.mpr h x == x :=
692-
by subst h; refl
693-
694696
protected lemma eq.congr {x₁ x₂ y₁ y₂ : α} (h₁ : x₁ = y₁) (h₂ : x₂ = y₂) :
695697
(x₁ = x₂) ↔ (y₁ = y₂) :=
696698
by { subst h₁, subst h₂ }

src/logic/function/basic.lean

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,33 @@ def set.piecewise {α : Type u} {β : α → Sort v} (s : set α) (f g : Πi, β
610610
Πi, β i :=
611611
λi, if i ∈ s then f i else g i
612612

613+
/-! ### Bijectivity of `eq.rec`, `eq.mp`, `eq.mpr`, and `cast` -/
614+
615+
lemma eq_rec_on_bijective {α : Sort*} {C : α → Sort*} :
616+
∀ {a a' : α} (h : a = a'), function.bijective (@eq.rec_on _ _ C _ h)
617+
| _ _ rfl := ⟨λ x y, id, λ x, ⟨x, rfl⟩⟩
618+
619+
lemma eq_mp_bijective {α β : Sort*} (h : α = β) : function.bijective (eq.mp h) :=
620+
eq_rec_on_bijective h
621+
622+
lemma eq_mpr_bijective {α β : Sort*} (h : α = β) : function.bijective (eq.mpr h) :=
623+
eq_rec_on_bijective h.symm
624+
625+
lemma cast_bijective {α β : Sort*} (h : α = β) : function.bijective (cast h) :=
626+
eq_rec_on_bijective h
627+
628+
/-! Note these lemmas apply to `Type*` not `Sort*`, as the latter interferes with `simp`, and
629+
is trivial anyway.-/
630+
631+
@[simp]
632+
lemma eq_rec_inj {α : Sort*} {a a' : α} (h : a = a') {C : α → Type*} (x y : C a) :
633+
(eq.rec x h : C a') = eq.rec y h ↔ x = y :=
634+
(eq_rec_on_bijective h).injective.eq_iff
635+
636+
@[simp]
637+
lemma cast_inj {α β : Type*} (h : α = β) {x y : α} : cast h x = cast h y ↔ x = y :=
638+
(cast_bijective h).injective.eq_iff
639+
613640
/-- A set of functions "separates points"
614641
if for each pair of distinct points there is a function taking different values on them. -/
615642
def separates_points {α β : Type*} (A : set (α → β)) : Prop :=

src/tactic/interactive.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ do let (e,n) := arg,
595595
tactic.clear h' ),
596596
when h.is_some (do
597597
(to_expr ``(heq_of_eq_rec_left %%eq_h %%asm)
598-
<|> to_expr ``(heq_of_eq_mp %%eq_h %%asm))
598+
<|> to_expr ``(heq_of_cast_eq %%eq_h %%asm))
599599
>>= note h' none >> pure ()),
600600
tactic.clear asm,
601601
when rev.is_some (interactive.revert [n])

src/tactic/transport.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ It's probably best not to adjust it without understanding the algorithm used by
2727

2828
attribute [transport_simps]
2929
eq_rec_constant
30-
eq_mpr_rfl
30+
eq_mp_eq_cast
31+
cast_eq
3132
equiv.to_fun_as_coe
3233
equiv.arrow_congr'_apply
3334
equiv.symm_apply_apply

test/equiv_rw.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ mk_simp_attribute transport_simps "simps useful inside `transport`"
287287

288288
attribute [transport_simps]
289289
eq_rec_constant
290-
eq_mpr_rfl
290+
cast_eq
291291
equiv.to_fun_as_coe
292292
equiv.arrow_congr'_apply
293293
equiv.symm_apply_apply

0 commit comments

Comments
 (0)