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(Ico): initial implementation of intervals in nat [WIP] #496

Closed

Conversation

semorrison
Copy link
Collaborator

Some initial attempts at defining Ico (interval, closed-open), in nat, as a list, multiset, and finset.

There are many more lemmas to prove about these intervals (and the corresponding ones in int), but these are all I need so far for my "reindexing finset.sum" lemmas and tactics.

(And I think this stuff will be useful whatever our eventual design for big operators looks like.)

Please feel free to criticize, hack, or add to this branch!

data/finset.lean Outdated Show resolved Hide resolved
@johoelzl johoelzl added the WIP Work in progress label Jan 10, 2019
data/list/basic.lean Outdated Show resolved Hide resolved
data/finset.lean Outdated Show resolved Hide resolved
@johoelzl
Copy link
Collaborator

(Note: I didn't try the proof myself)

I would suggest to prove first more general rules about Ico on lists:
n <= m <= k -> Ico n m ++ Ico m k = Ico n k
This also translates nicely to multiset and finset. On the other hand, I think all proofs you have in multiset should be there also for lists.

Then we can proof:

n <= l <= m ->
(Ico n m).filter (λ x, x < l) =
(Ico n l).filter (λ x, x < l) ++ (Ico l m).filter (λ x, x < l) =
(Ico n l).filter (λ x, x < l)

src/data/multiset.lean Outdated Show resolved Hide resolved
@@ -4038,7 +4038,14 @@ by dsimp [Ico]; simp [nat.add_sub_cancel_left]
theorem pred_singleton {m : ℕ} (h : m > 0) : Ico (m-1) m = [m-1] :=
by dsimp [Ico]; rw nat.sub_sub_self h; simp

-- Someone put me out of my misery (no human suffering should be needed to prove this):
theorem gt_nil {n m : ℕ} (h : n > m) : Ico n m = [] :=
Copy link
Collaborator

Choose a reason for hiding this comment

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

this holds more general for n >= m, also I would call it eq_nil_of_le

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, thanks.

@semorrison
Copy link
Collaborator Author

(Note: I didn't try the proof myself)

I would suggest to prove first more general rules about Ico on lists:
n <= m <= k -> Ico n m ++ Ico m k = Ico n k
This also translates nicely to multiset and finset. On the other hand, I think all proofs you have in multiset should be there also for lists.

Then we can proof:

n <= l <= m ->
(Ico n m).filter (λ x, x < l) =
(Ico n l).filter (λ x, x < l) ++ (Ico l m).filter (λ x, x < l) =
(Ico n l).filter (λ x, x < l)

Thanks for this. As it turned out I independently realised this was the way to go, and implemented this approach last night.

@johoelzl johoelzl closed this in 7baf093 Jan 22, 2019
@johoelzl johoelzl deleted the finset-interval branch January 22, 2019 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants