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] - feat(data/rat/basic): Add nat num and denom inv lemmas #8581

Closed
wants to merge 4 commits into from

Conversation

FrickHazard
Copy link
Collaborator

@FrickHazard FrickHazard commented Aug 8, 2021

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.


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.

Open in Gitpod

@FrickHazard FrickHazard added easy < 20s of review time. See the lifecycle page for guidelines. awaiting-review The author would like community review of the PR labels Aug 8, 2021
@bryangingechen bryangingechen changed the title feat(rat.basic): Add nat num and denom inv lemmas feat(data/rat/basic): Add nat num and denom inv lemmas Aug 8, 2021
src/data/rat/basic.lean Outdated Show resolved Hide resolved
Comment on lines 747 to 755
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
Copy link
Member

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:

Suggested change
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?

Copy link
Collaborator Author

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.

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors d+

Thanks!

@bors
Copy link

bors bot commented Aug 11, 2021

✌️ FrickHazard can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@github-actions github-actions bot added delegated The PR author may merge after reviewing final suggestions. and removed awaiting-review The author would like community review of the PR labels Aug 11, 2021
@FrickHazard
Copy link
Collaborator Author

bors r+

bors bot pushed a commit that referenced this pull request Aug 11, 2021
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>
@bors
Copy link

bors bot commented Aug 11, 2021

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(data/rat/basic): Add nat num and denom inv lemmas [Merged by Bors] - feat(data/rat/basic): Add nat num and denom inv lemmas Aug 11, 2021
@bors bors bot closed this Aug 11, 2021
@bors bors bot deleted the nat_num_denom_inv branch August 11, 2021 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
delegated The PR author may merge after reviewing final suggestions. easy < 20s of review time. See the lifecycle page for guidelines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants