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

feat (data/pnat): extensions to pnat #1073

Merged
merged 24 commits into from Jun 10, 2019

Conversation

NeilStrickland
Copy link
Contributor

@NeilStrickland NeilStrickland commented May 21, 2019

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

  1. I created a new directory data/pnat and moved most material to the files basic.lean, factors.lean and xgcd.lean
  2. A small amount of material moved to data/nat/primes.lean instead
  3. These changes ensured that multiset.cons is no longer in scope in data/hashmap.lean, allowing me to revert the changes that I made to that file to disambiguate the notation a :: l.

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:

  • reviewed and applied the coding style: coding, naming
  • for tactics:
  • make sure definitions and lemmas are put in the right files
  • make sure definitions and lemmas are not redundant

If this PR is related to a discussion on Zulip, please include a link in the discussion.

For reviewers: code review check list

Copy link
Member

@jcommelin jcommelin left a 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.

src/data/pnat.lean Outdated Show resolved Hide resolved
src/data/hash_map.lean Outdated Show resolved Hide resolved
src/data/pnat.lean Outdated Show resolved Hide resolved
src/data/pnat.lean Outdated Show resolved Hide resolved
src/data/pnat.lean Outdated Show resolved Hide resolved
src/data/pnat.lean Outdated Show resolved Hide resolved
src/data/pnat.lean Outdated Show resolved Hide resolved
src/data/pnat.lean Outdated Show resolved Hide resolved
we used the general monoid version.
-/
instance : has_pow ℕ+ ℕ := ⟨λ n m, ⟨n.1 ^ m, nat.pow_pos n.2 m⟩⟩

Copy link
Member

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

Copy link
Contributor Author

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.

@mergify mergify bot dismissed ChrisHughes24’s stale review May 23, 2019 15:48

Pull request has been modified.

Copy link
Member

@ChrisHughes24 ChrisHughes24 left a 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

theorem is_reduced_iff : u.is_reduced ↔ u.is_reduced' :=
⟨congr_arg succ_pnat, succ_pnat_inj⟩

def flip' : ℕ × ℕ → ℕ × ℕ := λ v, ⟨v.2, v.1⟩
Copy link
Member

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

Copy link
Contributor Author

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


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
Copy link
Member

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.

Copy link
Contributor Author

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.

@mergify mergify bot dismissed ChrisHughes24’s stale review June 9, 2019 22:18

Pull request has been modified.

@ChrisHughes24 ChrisHughes24 merged commit 004e0b3 into leanprover-community:master Jun 10, 2019
anrddh pushed a commit to anrddh/mathlib that referenced this pull request May 15, 2020
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants