Skip to content

[Merged by Bors] - feat: tfae_have ... := syntax - #10653

Closed
thorimur wants to merge 23 commits into
masterfrom
tfae-have-stx-tweak
Closed

thorimur wants to merge 23 commits into
masterfrom
tfae-have-stx-tweak

Conversation

@thorimur

@thorimur thorimur commented Feb 17, 2024 •

Copy link
Copy Markdown
Contributor

This PR refactors tfae_have in terms of have, thus supporting all the syntax that have supports. We can now also write:

example : TFAE [P, Q, R] := by
  tfae_have 1 → 2 := sorry
  tfae_have 2 → 1
  | p => f p
  tfae_have ⟨mp, mpr⟩ : 2 ↔ 3 := sorry
  ...

Previously, tfae_have exclusively pushed a new goal to the top of the goal list, requiring that the result be proved via tactic.

This PR does not deprecate or remove the "old-style" syntax, but does de-document it. The removal of old-style syntax is done in #11000.

This tees us up for a tfae block tactic (#10991, #11003).

See Zulip.


Ref #2061

Open in Gitpod

Comment thread Mathlib/Tactic/TFAE.lean Outdated
@thorimur thorimur added t-meta Tactics, attributes or user commands awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. labels Feb 17, 2024
@github-actions github-actions Bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Feb 17, 2024
@thorimur thorimur added awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. awaiting-review labels Feb 17, 2024
@github-actions github-actions Bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Feb 17, 2024
Comment thread Mathlib/Tactic/TFAE.lean
Comment thread Mathlib/Tactic/TFAE.lean Outdated
Comment thread Mathlib/Tactic/TFAE.lean Outdated
@thorimur
thorimur force-pushed the tfae-have-stx-tweak branch from 8c3adb8 to fba28f5 Compare February 18, 2024 09:52
@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Feb 21, 2024
@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Feb 26, 2024
@thorimur thorimur mentioned this pull request Feb 26, 2024
2 tasks done
@thorimur thorimur added the modifies-tactic-syntax This PR adds a new interactive tactic or modifies the syntax of an existing tactic. label Feb 26, 2024
@urkud
urkud requested a review from eric-wieser June 15, 2024 16:10
@github-actions

github-actions Bot commented Jun 15, 2024 •

Copy link
Copy Markdown

PR summary aa408695b3

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ elabTFAEType
+ mkTFAEId
- mkImplType
- mkTFAEHypName
- tfaeHaveCore

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.

@ghost ghost removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jun 15, 2024
@urkud

urkud commented Jun 15, 2024

Copy link
Copy Markdown
Member

@thorimur I merged master, now it fails to compile.

@urkud urkud added awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. and removed awaiting-review labels Jun 15, 2024
@thorimur

Copy link
Copy Markdown
Contributor Author

@urkud Ah, thanks; I had given up on keeping this PR fresh! I'll take a look soon.

@ghost ghost added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jul 1, 2024
@thorimur thorimur removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 12, 2024
@leanprover-community-bot-assistant leanprover-community-bot-assistant removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 12, 2024
@thorimur

Copy link
Copy Markdown
Contributor Author

@urkud "Soon" has finally arrived. :) I've freshened this PR and its 3 dependents as well.

Comment thread Mathlib/Tactic/TFAE.lean Outdated
Comment on lines +299 to +307
-- Mathlib `have`
| `(tfaeHave'|tfae_have $d:tfaeHaveIdLhs) => withMainContext do
let goal ← getMainGoal
let (_, tfaeList) ← getTFAEList (← goal.getType)
match d with
| `(tfaeHaveIdLhs| $b:ident : $t:tfaeType) =>
let type ← elabTFAEType tfaeList t
evalTactic <|← `(tactic|have $b:ident : $(← exprToSyntax type))
| _ => throwUnsupportedSyntax

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the current consensus is that the mathlib-have should not be used inside mathlib anymore, and therefore ideally also not imported (see docs):

As a style choice, this [mathlib's have] should not be used in mathlib; but is provided for downstream users who preferred the old style.

Maybe it's easiest to just drop the import together with this snippet?

Or is there a reasonable workaround which allows not to import the modified have here?

@thorimur thorimur Sep 18, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, that's right. :) I eliminated the import and moved the entirety of the old-style version to its own section below.

In parallel to Mathlib have, I think we ought to move the old tfae_have syntax to its own non-imported file in the PR that migrates Mathlib to the new syntax (#11000); what do you think?

@joneugster joneugster self-assigned this Sep 17, 2024
Comment thread Mathlib/Tactic/TFAE.lean
Comment on lines +260 to +268
/- Convert `tfae_have i <arr> j ...` to `tfae_have tfae_i_arr_j : i <arr> j ...`. See
`expandHave`, which is responsible for inserting `this` in `have : A := ...`. -/
macro_rules
| `(tfaeHave|tfae_have $hy:hygieneInfo $t:tfaeType := $val) => do
let id := HygieneInfo.mkIdent hy (← mkTFAEId t) (canonical := true)
`(tfaeHave|tfae_have $id : $t := $val)
| `(tfaeHave|tfae_have $hy:hygieneInfo $t:tfaeType $alts:matchAlts) => do
let id := HygieneInfo.mkIdent hy (← mkTFAEId t) (canonical := true)
`(tfaeHave|tfae_have $id : $t $alts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be better to do this inside the elab and use Lean.Meta.mkFreshBinderNameForTactic in order to make the tactic hygienic.

I.e. the binder name should probably only be accessible if set_option tactic.hygienic false

@thorimur thorimur Sep 18, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure—tfae_have is specifically meant to mimic have when the binder name is not provided, which means producing an accessible name like tfae_2_iff_3 in analogy to producing the accessible name this. (Note that this is the same mechanism used by have to accomplish that.)

(This is also how it currently behaves, so I'd be wary of breaking it!)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok that's a fair point!

@joneugster joneugster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR. I think it looks very clean and will be a good base for the upcoming improvements for the tfae tactic. I suggest

maintainer merge

@github-actions

Copy link
Copy Markdown

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

@github-actions github-actions Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Sep 18, 2024
@urkud

urkud commented Sep 20, 2024

Copy link
Copy Markdown
Member

LGTM. We can fix issues (if any) in the PR migrating Mathlib to the new syntax. Thanks a lot!
bors merge

@github-actions github-actions Bot added the ready-to-merge This PR has been sent to bors. label Sep 20, 2024
mathlib-bors Bot pushed a commit that referenced this pull request Sep 20, 2024
This PR refactors `tfae_have` in terms of `have`, thus supporting all the syntax that `have` supports. We can now also write:
```lean
example : TFAE [P, Q, R] := by
  tfae_have 1 → 2 := sorry
  tfae_have 2 → 1
  | p => f p
  tfae_have ⟨mp, mpr⟩ : 2 ↔ 3 := sorry
  ...
```
Previously, `tfae_have` exclusively pushed a new goal to the top of the goal list, requiring that the result be proved via tactic.

This PR does not deprecate or remove the "old-style" syntax, but does de-document it. The removal of old-style syntax is done in #11000.

This tees us up for a `tfae` block tactic (#10991, #11003).

See [Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/tfae_have.201.20.E2.86.92.202.20.3A.3D.20syntax).



Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
@mathlib-bors

mathlib-bors Bot commented Sep 20, 2024

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title feat: tfae_have ... := syntax [Merged by Bors] - feat: tfae_have ... := syntax Sep 20, 2024
@mathlib-bors mathlib-bors Bot closed this Sep 20, 2024
@mathlib-bors
mathlib-bors Bot deleted the tfae-have-stx-tweak branch September 20, 2024 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. modifies-tactic-syntax This PR adds a new interactive tactic or modifies the syntax of an existing tactic. 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.

6 participants