Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

feat(tactic/expand_exists): create in namespace & docstring #15732

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

0x182d4454fb211940
Copy link
Collaborator

expand_exists now creates definitions in the same namespace as the lemma, and allows creating docstrings.

Closes #15723.


Open in Gitpod

@0x182d4454fb211940
Copy link
Collaborator Author

0x182d4454fb211940 commented Jul 28, 2022

It's worth noting this is a breaking change for anyone who was using namespaces. It would be possible to reverse it (i.e. by default use the root namespace, to stay backwards-comptable), but I think this is the obvious behaviour, and I can't see any use of the attribute yet in the master branch.

@0x182d4454fb211940
Copy link
Collaborator Author

The = docstring syntax is used because otherwise it seems like failure is unrecoverable. Calling parser.pexpr when what remains isn't a string (eg @[expand_exists name_a name_b], with cursor between names) brings up an error stating that name_b is an unknown identifier.

src/tactic/expand_exists.lean Outdated Show resolved Hide resolved
the name:

```lean
@[expand_exists foo="a foo with property bar" bar]
Copy link
Member

Choose a reason for hiding this comment

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

An alternative syntax -- but this time I'm not sure if it's better -- @[expand_exists [foo "a foo with property bar", bar]]. This should also avoid any pexpr/name ambiguity and is easy enough to parse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't tried implementing this yet but I'm a bit torn: it seems cleaner but also slightly more verbose and less like other attribute syntaxes. I guess it would be possible to accept both but I think that just adds maintenance burden. I also imagine your proposed syntax could allow for more features more gracefully in future? Again, I'm unsure.

Copy link
Member

Choose a reason for hiding this comment

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

We definitely shouldn't support both = and lists. In favor of the list syntax: lists are already used in some attributes (@[derive [class1, class2]]), and = is not AFAIK. Against the list syntax, in the no-doc-strings case, it clashes with the syntax for e.g. simps (@[simps id1 id2 id3] vs @[expand_exists [id1, id2, id3]]).

Maybe the move is to support both the bare stream of idents (without doc strings at all) and the more verbose list style? Something like parse (ident* <|> list_of ident_with_opt_string), see https://github.com/leanprover-community/lean/blob/22b09be35ef66aece11e6e8f5d114f42b064259b/library/init/meta/interactive_base.lean#L61 .

@digama0 any preference here?

Copy link
Member

@digama0 digama0 Jul 28, 2022

Choose a reason for hiding this comment

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

I think the simplest approach would be to simply copy the docstring from the theorem to all generated declarations. That way you don't have to shove a doc string into the middle of an attribute. For lean 4, I would probably be looking at a syntax closer to

expand_exists ⟨
  /-- doc string -/ defn,
  /-- doc string -/ thm
⟩ (param : type) : type -> \exists x, p x := proof

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps it makes sense for now to use the docstring with the exists lemma by default, allow the = syntax for now to override this, and add a note stating the planned syntax for lean 4?

Copy link
Member

Choose a reason for hiding this comment

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

Whatever choice we make here could be retrospectively applied to simps, since in principle we could want to set docstrings there too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@robertylewis Interestingly that worked but only the other way around (trying to parse as a list, then falling back to idents). I don't really understand what would cause this behaviour: is there some intentional design decision behind this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@digama0 One other idea is we could have an auto-generated string saying something like "See exists_lemma" provided it has a docstring, though either approach would work. Both are quite easy to implement.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it makes sense for now to use the docstring with the exists lemma by default, allow the = syntax for now to override this, and add a note stating the planned syntax for lean 4?

I still don't love the = syntax, but this sounds fine to me. It's not really worth quibbling over! I think this is better than

@digama0 One other idea is we could have an auto-generated string saying something like "See exists_lemma" provided it has a docstring, though either approach would work. Both are quite easy to implement.

since it's best for doc strings to be self-contained whenever possible, since they show up in hover tooltips.

Copy link
Member

Choose a reason for hiding this comment

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

@robertylewis Interestingly that worked but only the other way around (trying to parse as a list, then falling back to idents). I don't really understand what would cause this behaviour: is there some intentional design decision behind this?

I would have expected it to work either way since an ident can't start with [. Can't say why without playing around with it myself!

@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes t-meta Tactics, attributes or user commands modifies-tactic-syntax This PR adds a new interactive tactic or modifies the syntax of an existing tactic. labels Jul 28, 2022
@robertylewis robertylewis self-assigned this Aug 10, 2022
@kim-em kim-em added the too-late This PR was ready too late for inclusion in mathlib3 label Jul 16, 2023
@eric-wieser eric-wieser requested a review from a team as a code owner October 16, 2023 15:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting-author A reviewer has asked the author a question or requested changes modifies-tactic-syntax This PR adds a new interactive tactic or modifies the syntax of an existing tactic. t-meta Tactics, attributes or user commands too-late This PR was ready too late for inclusion in mathlib3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expand_exists improvements
5 participants