Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - chore(data/{nat,int,rat}/cast): add bundled version of cast_id lemmas #13001

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/data/int/cast.lean
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ ext_iff.1 (f.eq_int_cast_hom h1)

end add_monoid_hom

@[simp] lemma int.cast_add_hom_int : int.cast_add_hom ℤ = add_monoid_hom.id ℤ :=
((add_monoid_hom.id ℤ).eq_int_cast_hom rfl).symm

namespace monoid_hom
variables {M : Type*} [monoid M]
open multiplicative
Expand Down Expand Up @@ -303,6 +306,9 @@ end ring_hom
@[simp, norm_cast] theorem int.cast_id (n : ℤ) : ↑n = n :=
((ring_hom.id ℤ).eq_int_cast n).symm

@[simp] lemma int.cast_ring_hom_int : int.cast_ring_hom ℤ = ring_hom.id ℤ :=
(ring_hom.id ℤ).eq_int_cast'.symm

namespace pi

variables {α β : Type*}
Expand Down
15 changes: 13 additions & 2 deletions src/data/nat/cast.lean
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,28 @@ ext_nat' f g $ by simp only [map_one]

end ring_hom_class

namespace ring_hom

/-- This is primed to match `ring_hom.eq_int_cast'`. -/
@[simp] lemma eq_nat_cast' {R} [non_assoc_semiring R] (f : ℕ →+* R) : f = nat.cast_ring_hom R :=
eric-wieser marked this conversation as resolved.
Show resolved Hide resolved
ring_hom.ext $ eq_nat_cast f

end ring_hom

@[simp, norm_cast] theorem nat.cast_id (n : ℕ) : ↑n = n :=
(eq_nat_cast (ring_hom.id ℕ) n).symm

@[simp] lemma nat.cast_ring_hom_nat : nat.cast_ring_hom ℕ = ring_hom.id ℕ :=
((ring_hom.id ℕ).eq_nat_cast').symm

@[simp] theorem nat.cast_with_bot : ∀ (n : ℕ),
@coe ℕ (with_bot ℕ) (@coe_to_lift _ _ nat.cast_coe) n = n
| 0 := rfl
| (n+1) := by rw [with_bot.coe_add, nat.cast_add, nat.cast_with_bot n]; refl

-- I don't think `ring_hom_class` is good here, because of the `subsingleton` TC slowness
instance nat.subsingleton_ring_hom {R : Type*} [non_assoc_semiring R] : subsingleton (ℕ →+* R) :=
⟨ext_nat⟩
instance nat.unique_ring_hom {R : Type*} [non_assoc_semiring R] : unique (ℕ →+* R) :=
{ default := nat.cast_ring_hom R, uniq := ring_hom.eq_nat_cast' }

namespace mul_opposite

Expand Down
3 changes: 3 additions & 0 deletions src/data/rat/cast.lean
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ by rw [← cast_zero, cast_lt]
@[simp, norm_cast] theorem cast_id : ∀ n : ℚ, ↑n = n
| ⟨n, d, h, c⟩ := by rw [num_denom', cast_mk, mk_eq_div]

@[simp] lemma cast_hom_rat : cast_hom ℚ = ring_hom.id ℚ :=
ring_hom.ext cast_id

@[simp, norm_cast] theorem cast_min [linear_ordered_field α] {a b : ℚ} :
(↑(min a b) : α) = min a b :=
by by_cases a ≤ b; simp [h, min_def]
Expand Down