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

command to unpack an existential with classical.some #11682

Closed
robertylewis opened this issue Jan 27, 2022 · 6 comments
Closed

command to unpack an existential with classical.some #11682

robertylewis opened this issue Jan 27, 2022 · 6 comments
Labels
feature-request This issue is a feature request, either for mathematics, tactics, or CI good-first-project t-meta Tactics, attributes or user commands

Comments

@robertylewis
Copy link
Member

I've recently found myself repeating this pattern a bunch:

lemma it_exists (a b c d) : ∃ x : T, property x :=
long proof

def it (a b c d) : T := classical.some (it_exists a b c d)

lemma it_spec (a b c d) : property (it a b c d) := classical.some_spec (it_exists a b c d)

It would be relatively easy to write a metaprogram that automatically generates it and it_spec from it_exists. This could be run with an atribute on it_exists and/or a command afterward:

@[make_a_thing it it_spec]
lemma it_exists (a b c d) : ∃ x : T, property x :=
long proof
lemma it_exists (a b c d) : ∃ x : T, property x :=
long proof

make_a_thing it_exists it it_spec

Note: the type of it_spec is defeq, but not syntactically equal, to the type of classical.some_spec (it_exists a b c d).

@robertylewis robertylewis added t-meta Tactics, attributes or user commands feature-request This issue is a feature request, either for mathematics, tactics, or CI good-first-project labels Jan 27, 2022
@fpvandoorn
Copy link
Member

If I can extend your feature request: it would be nice if it could also deal with statements like ∃ (x : T) (y : S), P x y ∧ Q y x and make more than 2 declarations (in this case 4).

@fpvandoorn
Copy link
Member

Note: the implementation of tactic.choose is very likely to be helpful to implement this.

@ericrbg
Copy link
Collaborator

ericrbg commented Jan 28, 2022

@fpvandoorn what declarations would you expect it to make? I feel like I'm missing something fairly obvious here

@fpvandoorn
Copy link
Member

fpvandoorn commented Jan 31, 2022

If I prove it_exists : (list_of_variables : list_of_types) : ∃ (x : T) (y : S), P x y ∧ Q y x I want something like the following (probably with customizable names)

def it1 (l : _) : T := classical.some $ it_exists l
def it2 (l : _) : S := classical.some $ classical.some_spec $ it_exists l
lemma it_spec1 (l : _) : P (it1 l) (it2 l) := (classical.some_spec $ classical.some_spec $ it_exists l).1
lemma it_spec2 (l : _) : Q (it2 l) (it1 l) := (classical.some_spec $ classical.some_spec $ it_exists l).2

Here is an example where that would be useful (though in that code I also did some other things that weren't purely "use classical.some[_spec]")

@0x182d4454fb211940
Copy link
Collaborator

I have an implementation. Do I need to ask on zulip to open a PR?

@fpvandoorn
Copy link
Member

I sent you an invitation so that you can push to a branch of mathlib. Please read https://leanprover-community.github.io/contribute/index.html and open an PR.

@bors bors bot closed this as completed in f9153b8 Jul 20, 2022
joelriou pushed a commit that referenced this issue Jul 23, 2022
Adds an attribute `expand_exists`, which takes a proof that something exists with some property, and outputs a value using `classical.some`, and a proof that it has that property using `classical.some_spec`.

Closes #11682
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This issue is a feature request, either for mathematics, tactics, or CI good-first-project t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants