-
Notifications
You must be signed in to change notification settings - Fork 297
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] - feat(data/rat/basic): Add nat num and denom inv lemmas #8581
Conversation
src/data/rat/basic.lean
Outdated
lemma inv_coe_nat_num {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 := | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this proof is simpler if you prove it for int
first:
lemma inv_coe_nat_num {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 := | |
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 inv_coe_int_num {a : ℤ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 := | |
begin | |
rw [rat.inv_def', rat.coe_int_num, rat.coe_int_denom, nat.cast_one, ←int.cast_one], | |
apply num_div_eq_of_coprime ha0, | |
rw int.nat_abs_one, | |
exact nat.coprime_one_left _, | |
end | |
lemma inv_coe_nat_num {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 := | |
inv_coe_int_num (by exact_mod_cast ha0 : 0 < (a : ℤ)) |
Can you do the same for the lemma below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thanks for the feedback! I updated your golf and added inv_coe_int_denom
. The nat version of the proof uses an additional exact_mod_cast
, because of casting the denom, which is a nat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors d+
Thanks!
✌️ FrickHazard can now approve this pull request. To approve and merge a pull request, simply reply with |
bors r+ |
Add `inv_coe_nat_num` and `inv_coe_nat_denom` lemmas. These lemmas show that the denominator and numerator of `1/ n` given `0 < n`, are equal to `n` and `1` respectively. Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Pull request successfully merged into master. Build succeeded: |
Add
inv_coe_nat_num
andinv_coe_nat_denom
lemmas.These lemmas show that the denominator and numerator of
1/ n
given0 < n
, are equal ton
and1
respectively.Hello All👋, this is my first PR. I am working a project where I formalized the results for thomae's function. This lemma was necessary and seemed fundamental enough to rationals, to make a PR.
The lemmas are the following, 0 < n, 1/n .denom = n and 1/n.num = 1
Was done with collaboration with Xena and in particular Kevin buzzard.