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/Fin/Tuple): Define Fin.take and initial theorems #17196

Closed
wants to merge 20 commits into from

Conversation

quangvdao
Copy link
Collaborator

@quangvdao quangvdao commented Sep 28, 2024

This PR defines Fin.take, which takes the first m elements of an n-tuple (from the left). It requires that m ≤ n, and returns an m-tuple. This is an analogue of List.take.

It also provides initial theorems for Fin.take. If all goes well, I plan to add more theorems over time, and also define rtake to be taking from the right, similar to List.rtake.

Context: I'm working on a formalization of interactive proof systems. As part of that process, I need to define the type of message sent in each round, as something like:

def MessageType (numRounds : ℕ) := Fin numRounds → Type
def message (numRounds : ℕ) : ∀ i, (MessageType numRounds) i

Then I will also need to talk about composition and restriction of interactive protocols. Composition amounts to Fin.addCases, but restriction is my new Fin.take, and also Fin.rtake in the future (taking from the right).


Open in Gitpod

@github-actions github-actions bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Sep 28, 2024
Copy link

github-actions bot commented Sep 28, 2024

PR summary f508575c15

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Data.Fin.Tuple.Take 336

Declarations diff

+ get_take_eq_take_get_comp_cast
+ get_take_ofFn_eq_take_comp_cast
+ ofFn_take_eq_take_ofFn
+ ofFn_take_get
+ take
+ take_addCases_left
+ take_addCases_right
+ take_append_left
+ take_append_right
+ take_apply
+ take_eq_init
+ take_eq_self
+ take_init
+ take_one
+ take_repeat
+ take_succ_eq_snoc
+ take_take
+ take_update_of_ge
+ take_update_of_lt
+ take_zero

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.

@github-actions github-actions bot added the t-data Data (lists, quotients, numbers, etc) label Sep 28, 2024
Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

What's your use case for Fin.take?

Mathlib/Data/Fin/Tuple/Basic.lean Outdated Show resolved Hide resolved
Mathlib/Data/Fin/Tuple/Basic.lean Outdated Show resolved Hide resolved
@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes label Oct 16, 2024
@quangvdao
Copy link
Collaborator Author

What's your use case for Fin.take?

I'm working on a formalization of interactive proof systems. As part of that process, I need to define the type of message sent in each round, as something like:

def MessageType (numRounds : ℕ) := Fin numRounds → Type
def message (numRounds : ℕ) : ∀ i, (MessageType numRounds) i

Then I will also need to talk about composition and restriction of interactive protocols. Composition amounts to Fin.addCases, but restriction is my new Fin.take, and also Fin.rtake in the future (taking from the right).

@YaelDillies
Copy link
Collaborator

Seems reasonable, but let me ask among the reviewers which repository it should live in.

@quangvdao
Copy link
Collaborator Author

@kim-em I have added four theorems that intertwines Fin.take and List.take with List.get and List.ofFn. Two of the theorems have to be stated in terms of heterogeneous equality, since the types are only propeq:

/-- `Fin.take` intertwines with `List.take` via `List.get`. -/
theorem list_take_get_heq {α : Type*} {m : ℕ} (l : List α) (h : m ≤ l.length) :
    HEq (l.take m).get (take m h l.get) :=
  (Fin.heq_fun_iff (List.length_take_of_le h)).mpr (by simp)

/-- Alternative version of `list_take_get_heq` with `v : Fin n → α` instead of `l : List α`. -/
theorem list_ofFn_take_get_heq {α : Type*} {m : ℕ} (v : Fin n → α) (h : m ≤ n) :
    HEq ((List.ofFn v).take m).get (take m h v) :=
  (Fin.heq_fun_iff (by simp [h])).mpr (by simp)

Would appreciate your feedback on theorem statement & naming. Maybe I should get rid of heq in the name?

@quangvdao quangvdao removed the awaiting-author A reviewer has asked the author a question or requested changes label Oct 17, 2024
@fpvandoorn fpvandoorn removed their request for review October 23, 2024 09:29
Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

Thanks for your patience! The end is in sight.

Mathlib/Data/Fin/Tuple/Take.lean Outdated Show resolved Hide resolved
Mathlib/Data/Fin/Tuple/Take.lean Outdated Show resolved Hide resolved
Mathlib/Data/Fin/Tuple/Take.lean Outdated Show resolved Hide resolved
Mathlib/Data/Fin/Tuple/Take.lean Outdated Show resolved Hide resolved
Mathlib/Data/Fin/Tuple/Take.lean Outdated Show resolved Hide resolved
Mathlib/Data/Fin/Tuple/Take.lean Outdated Show resolved Hide resolved
Mathlib/Data/Fin/Tuple/Take.lean Outdated Show resolved Hide resolved
@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes label Oct 30, 2024
@quangvdao quangvdao removed the awaiting-author A reviewer has asked the author a question or requested changes label Oct 30, 2024
Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

I'm appy with this. What about you, @kim-em ?

maintainer merge

Copy link

🚀 Pull request has been placed on the maintainer queue by YaelDillies.

@kim-em
Copy link
Contributor

kim-em commented Oct 30, 2024

bors merge

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Oct 30, 2024
mathlib-bors bot pushed a commit that referenced this pull request Oct 31, 2024
This PR defines `Fin.take`, which takes the first `m` elements of an `n`-tuple (from the left). It requires that `m ≤ n`, and returns an `m`-tuple. This is an analogue of `List.take`.

It also provides initial theorems for `Fin.take`. If all goes well, I plan to add more theorems over time, and also define `rtake` to be taking from the right, similar to `List.rtake`.

Context: I'm working on a formalization of interactive proof systems. As part of that process, I need to define the type of message sent in each round, as something like:
```
def MessageType (numRounds : ℕ) := Fin numRounds → Type
def message (numRounds : ℕ) : ∀ i, (MessageType numRounds) i
```
Then I will also need to talk about composition and restriction of interactive protocols. Composition amounts to `Fin.addCases`, but restriction is my new `Fin.take`, and also `Fin.rtake` in the future (taking from the right).



Co-authored-by: Quang Dao <[email protected]>
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Oct 31, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat(Data/Fin/Tuple): Define Fin.take and initial theorems [Merged by Bors] - feat(Data/Fin/Tuple): Define Fin.take and initial theorems Oct 31, 2024
@mathlib-bors mathlib-bors bot closed this Oct 31, 2024
@mathlib-bors mathlib-bors bot deleted the fin-take branch October 31, 2024 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer-merge new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! ready-to-merge This PR has been sent to bors. t-data Data (lists, quotients, numbers, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants