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: term elaborator for associativity equivalences between iterated products. #8551

Closed
wants to merge 16 commits into from

Conversation

adamtopaz
Copy link
Contributor

@adamtopaz adamtopaz commented Nov 21, 2023

For example,

(prod_assoc% : (α × β) × (γ × δ) ≃ α × (β × γ) × δ)

gives the "obvious" equivalence between (α × β) × (γ × δ) and α × (β × γ) × δ.

Special thanks to @kmill for help getting the expected type to work in the elaborator!


Open in Gitpod

@adamtopaz adamtopaz added WIP Work in progress t-meta Tactics, attributes or user commands labels Nov 21, 2023
@adamtopaz adamtopaz added awaiting-review and removed WIP Work in progress labels Nov 21, 2023
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/ProdAssoc.lean Outdated Show resolved Hide resolved
Copy link
Contributor

@kmill kmill left a comment

Choose a reason for hiding this comment

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

Something that occurred to me is that we could have probably used the coherence theorem for monoidal categories and the coherence tactic to do all this "for free" (you're using List to strictify the products after all 😄) but I believe you're generating much much better code, if this elaborator gets used in programming.

I don't see any obvious bugs, so let's just merge

bors r+

There's one suggested efficiency improvement, but the arrays involved are so small we'd probably not detect the difference, though it would make the code look cleaner. I figure it can be a follow-up.


/-- This function should act as the "reverse" of `ProdTree.unpack`, constructing
a term of the iterated product out of a list of terms of the types appearing in the product. -/
def ProdTree.pack (ts : List Expr) : ProdTree → MetaM Expr
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you could make this take an Subarray Expr, which would save you needing to do these to-and-from-array conversions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I'll implement this in a follow up PR.

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review labels Nov 22, 2023
mathlib-bors bot pushed a commit that referenced this pull request Nov 22, 2023
… products. (#8551)

For example,
```lean
(prod_assoc% : (α × β) × (γ × δ) ≃ α × (β × γ) × δ)
```
gives the "obvious" equivalence between `(α × β) × (γ × δ)` and `α × (β × γ) × δ`.

Special thanks to @kmill for help getting the expected type to work in the elaborator!



Co-authored-by: Adam Topaz <adamtopaz@users.noreply.github.com>
@adamtopaz
Copy link
Contributor Author

@kmill the coherence stuff would have worked great if all the types had the same universe level. This approach doesn't have such a restriction 😁

@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Nov 22, 2023

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat: term elaborator for associativity equivalences between iterated products. [Merged by Bors] - feat: term elaborator for associativity equivalences between iterated products. Nov 22, 2023
@mathlib-bors mathlib-bors bot closed this Nov 22, 2023
@mathlib-bors mathlib-bors bot deleted the AT-prod-assoc branch November 22, 2023 01:23
grunweg pushed a commit that referenced this pull request Dec 15, 2023
… products. (#8551)

For example,
```lean
(prod_assoc% : (α × β) × (γ × δ) ≃ α × (β × γ) × δ)
```
gives the "obvious" equivalence between `(α × β) × (γ × δ)` and `α × (β × γ) × δ`.

Special thanks to @kmill for help getting the expected type to work in the elaborator!



Co-authored-by: Adam Topaz <adamtopaz@users.noreply.github.com>
awueth pushed a commit that referenced this pull request Dec 19, 2023
… products. (#8551)

For example,
```lean
(prod_assoc% : (α × β) × (γ × δ) ≃ α × (β × γ) × δ)
```
gives the "obvious" equivalence between `(α × β) × (γ × δ)` and `α × (β × γ) × δ`.

Special thanks to @kmill for help getting the expected type to work in the elaborator!



Co-authored-by: Adam Topaz <adamtopaz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has been sent to bors. t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants