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

[Merged by Bors] - feat(data/rat/basic): Add nat num and denom inv lemmas #8581

Closed
wants to merge 4 commits into from
Closed
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
20 changes: 20 additions & 0 deletions src/data/rat/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,26 @@ begin
coe_nat_div_self]
end

lemma num_inv_nat {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 :=
FrickHazard marked this conversation as resolved.
Show resolved Hide resolved
begin
rw [rat.inv_def', rat.coe_nat_num, rat.coe_nat_denom],
suffices : (((1 : ℤ) : ℚ) / (a : ℤ)).num = 1,
exact_mod_cast this,
apply num_div_eq_of_coprime,
{ assumption_mod_cast },
{ simp only [nat.coprime_one_left_iff, int.nat_abs_one] }
end

lemma denom_inv_nat {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.denom = a :=
begin
rw [rat.inv_def', rat.coe_nat_num, rat.coe_nat_denom],
suffices : ((((1 : ℤ) : ℚ) / (a : ℤ)).denom : ℤ) = a,
exact_mod_cast this,
apply denom_div_eq_of_coprime,
{ assumption_mod_cast },
{ simp only [nat.coprime_one_left_iff, int.nat_abs_one] },
end

protected lemma «forall» {p : ℚ → Prop} : (∀ r, p r) ↔ ∀ a b : ℤ, p (a / b) :=
⟨λ h _ _, h _,
λ h q, (show q = q.num / q.denom, from by simp [rat.div_num_denom]).symm ▸ (h q.1 q.2)⟩
Expand Down