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
feat (data/pnat): extensions to pnat #1073
feat (data/pnat): extensions to pnat #1073
Conversation
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 made some stylistic remarks so far. Also, I agree that it might make sense to start a pnat/
directory, and move things to pnat/basic
and pnat/xgcd
.
Co-Authored-By: Johan Commelin <johan@commelin.net>
Co-Authored-By: Johan Commelin <johan@commelin.net>
src/data/pnat/basic.lean
Outdated
we used the general monoid version. | ||
-/ | ||
instance : has_pow ℕ+ ℕ := ⟨λ n m, ⟨n.1 ^ m, nat.pow_pos n.2 m⟩⟩ | ||
|
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 don't think this is necessary. The main reason there's a separate has_pow
for nat is that it is in core. Having two separate definitions causes a few problems, so we should really use monoid.pow
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 have switched to using monoid.pow
, and put in a proof that coercion preserves powers.
Pull request has been modified.
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.
A few minor changes and then I'll merge
src/data/pnat/xgcd.lean
Outdated
theorem is_reduced_iff : u.is_reduced ↔ u.is_reduced' := | ||
⟨congr_arg succ_pnat, succ_pnat_inj⟩ | ||
|
||
def flip' : ℕ × ℕ → ℕ × ℕ := λ v, ⟨v.2, v.1⟩ |
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.
This is just prod.swap
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 have switched to using prod.swap
src/data/pnat/xgcd.lean
Outdated
|
||
theorem gcd_rel_right' : | ||
(gcd_w a b) * (gcd_b' a b) = succ_pnat ((gcd_y a b) * (gcd_a' a b)) := | ||
(gcd_props a b).2.2.2.2.1 |
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.
proofs shouldn't be indented.
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 have fixed this, and various other formatting issues.
Pull request has been modified.
* Extended API, especially divisibility and primes * Positive euclidean algorithm * Disambiguate overloaded :: * Tweak broken proof of flip_is_special * Change to mathlib style * Update src/data/pnat.lean Co-Authored-By: Johan Commelin <johan@commelin.net> * Update src/data/pnat.lean Co-Authored-By: Johan Commelin <johan@commelin.net> * Adjust style for mathlib * Moved and renamed * Move some material from basic.lean to prime.lean * Move some material from basic.lean to factors.lean * Update import to data.pnat.basic. * Update import to data.pnat.basic * Fix import of data.pnat.basic * Use monoid.pow instead of nat.pow * Fix pnat.pow_succ -> pow_succ; stylistic changes * More systematic use of coercion * More consistent use of coercion * Formatting; change flip' to prod.swap
This adds lots of thing to the type pnat of positive integers. Many of them are related
to divisibility and prime factorization, which work most nicely in the pnat context.
Specifically, we construct an equivalence between pnat and the type of multisets
of primes, and prove that this respects various structures. This is closely related
to the content of ring_theory/unique_factorization_domain.lean, but not quite
the same because there are no units and so factorization is actually unique.
There is also (in pnat_xgcd.lean) a version of the extended Euclidean algorithm that
works purely in nat and pnat rather than int. This is useful because it interacts well
with the theory of continued fractions and the structure theory of SL_2(N).
Moreover, there is a clear uniqueness property for the output of this algorithm,
which is not so obvious for the integer version.
UPDATE: after the original version of this PR
This is my first attempt to add any meaningful content to mathlib. Please let me know if there are general things that I should be doing differently.
TO CONTRIBUTORS:
Make sure you have:
If this PR is related to a discussion on Zulip, please include a link in the discussion.
For reviewers: code review check list