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: the 'hint' tactic #8363

Closed
wants to merge 11 commits into from
Closed

Conversation

semorrison
Copy link
Contributor

example (h : 1 < 0) : False := by hint
example {P Q : Prop} (p : P) (f : P → Q) : Q := by hint
example {P Q R: Prop} (x : P ∧ Q ∧ R ∧ R) : Q ∧ P ∧ R := by hint
example {a b : ℚ} (h : a < b) : ¬ b < a := by hint
example : 37^2 - 35^2 = 72 * 2 := by hint
example : Nat.Prime 37 := by hint

Tries out any tactics registered using register_hint tac, and reports which ones succeed using the new "Try these: " multiple suggestion widgets. Tactics that close the goal are highlighted in green. Tactics that succeed but don't close the goal display the new subgoals in the widget. If tac produces a "Try this: " message, use that instead of tac.

I haven't hooked up aesop yet, because of leanprover-community/aesop#85. Similarly for norm_num.

I would like to parallelize this, but I don't think that needs to happen right away.


Open in Gitpod

@semorrison semorrison added awaiting-review The author would like community review of the PR awaiting-CI labels Nov 12, 2023
@timotree3
Copy link
Collaborator

How does this compare with #5363?

@semorrison
Copy link
Contributor Author

semorrison commented Nov 13, 2023

How does this compare with #5363?

Oh! I had completely failed to notice that. Apologies in particular to @Komyyy.

I'm impressed how parallel parts of the implementation are. :-) My version uses the new "Try these:" widget for providing multiple suggestions (edit: oh, so does @Komyyy's), and also does some additional post-processing to stop if it finds a tactic that closes the goal, and also shows the remaining subgoals for each suggestion in the widget.

@Komyyy, how should we proceed? Can we combine these into something better than either?

@semorrison
Copy link
Contributor Author

semorrison commented Nov 13, 2023

I will immediately steal the let tac : Syntax.Tactic := ⟨tac.raw.copyHeadTailInfoFrom .missing⟩ trick, which I presume solves the unreachable tactic warning.

Edit: nope. I wonder what it is for.

@Komyyy Komyyy added WIP Work in progress and removed awaiting-review The author would like community review of the PR labels Nov 14, 2023
@Komyyy Komyyy mentioned this pull request Nov 14, 2023
2 tasks
@Komyyy Komyyy added awaiting-review The author would like community review of the PR awaiting-CI and removed WIP Work in progress labels Nov 14, 2023
@Komyyy
Copy link
Collaborator

Komyyy commented Nov 14, 2023

I integrated my changes:

  1. Remove some placeholders for mathport
  2. Remove some comments for add_hint_tactic
  3. Align import
  4. Add an new process for register_hint to remove following comments
  5. Register the register_hint syntax as an exception of UnreachableTactic linter

@semorrison
Copy link
Contributor Author

Thank you, @Komyyy, and apologies again for missing your earlier PR.

@semorrison
Copy link
Contributor Author

Okay, I have a modification to this that runs all the hint tactics in parallel, and it's lovely. I still need to move some lemmas around to get the imports to work out, so we should merge this in the meantime.

Mathlib/Tactic/Common.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Hint.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Hint.lean Show resolved Hide resolved
test/hint.lean Show resolved Hide resolved
section Hint

register_hint split
register_hint intro
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should tauto be included here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At present there is no way to remove a register_hint (without PRing to Mathlib), but it is easy to add.

Can I suggest that intentionally undershoot on this PR, and then let people try it out and revise the list?

Comment on lines +128 to +129
register_hint exact?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
register_hint exact?
register_hint exact?
register_hint constructor

I think that Lean 3 had it and in Lean 4 is maybe more useful.
I wonder whether split_ifs is also an option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At present there is no way to remove a register_hint (without PRing to Mathlib), but it is easy to add.

Can I suggest that intentionally undershoot on this PR, and then let people try it out and revise the list?

@@ -254,7 +254,7 @@ def regular_check(lines, path):
if copy_done and line == "\n":
continue
words = line.split()
if words[0] != "import" and words[0] != "/-!" and words[0] != "#align_import":
if words[0] != "import" and words[0] != "--" and words[0] != "/-!" and words[0] != "#align_import":
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this should this be part of this PR, but if you think it's OK I'll let it slide.

I think this is a good first version of the tactic, and I'm happy if you merged it.

bors d+

@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Nov 16, 2023

✌️ semorrison can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@semorrison
Copy link
Contributor Author

bors merge

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review The author would like community review of the PR labels Nov 16, 2023
mathlib-bors bot pushed a commit that referenced this pull request Nov 16, 2023
```
example (h : 1 < 0) : False := by hint
example {P Q : Prop} (p : P) (f : P → Q) : Q := by hint
example {P Q R: Prop} (x : P ∧ Q ∧ R ∧ R) : Q ∧ P ∧ R := by hint
example {a b : ℚ} (h : a < b) : ¬ b < a := by hint
example : 37^2 - 35^2 = 72 * 2 := by hint
example : Nat.Prime 37 := by hint
```

Tries out any tactics registered using `register_hint tac`, and reports which ones succeed using the new "Try these: " multiple suggestion widgets. Tactics that close the goal are highlighted in green. Tactics that succeed but don't close the goal display the new subgoals in the widget. If `tac` produces a "Try this: " message, use that instead of `tac`.

I haven't hooked up `aesop` yet, because of leanprover-community/aesop#85. Similarly for `norm_num`.

I would like to parallelize this, but I don't think that needs to happen right away.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Co-authored-by: Komyyy <pol_tta@outlook.jp>
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Nov 16, 2023

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat: the 'hint' tactic [Merged by Bors] - feat: the 'hint' tactic Nov 16, 2023
@mathlib-bors mathlib-bors bot closed this Nov 16, 2023
@mathlib-bors mathlib-bors bot deleted the hint_tactic branch November 16, 2023 02:42
alexkeizer pushed a commit that referenced this pull request Nov 17, 2023
```
example (h : 1 < 0) : False := by hint
example {P Q : Prop} (p : P) (f : P → Q) : Q := by hint
example {P Q R: Prop} (x : P ∧ Q ∧ R ∧ R) : Q ∧ P ∧ R := by hint
example {a b : ℚ} (h : a < b) : ¬ b < a := by hint
example : 37^2 - 35^2 = 72 * 2 := by hint
example : Nat.Prime 37 := by hint
```

Tries out any tactics registered using `register_hint tac`, and reports which ones succeed using the new "Try these: " multiple suggestion widgets. Tactics that close the goal are highlighted in green. Tactics that succeed but don't close the goal display the new subgoals in the widget. If `tac` produces a "Try this: " message, use that instead of `tac`.

I haven't hooked up `aesop` yet, because of leanprover-community/aesop#85. Similarly for `norm_num`.

I would like to parallelize this, but I don't think that needs to happen right away.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Co-authored-by: Komyyy <pol_tta@outlook.jp>
alexkeizer pushed a commit that referenced this pull request Nov 21, 2023
```
example (h : 1 < 0) : False := by hint
example {P Q : Prop} (p : P) (f : P → Q) : Q := by hint
example {P Q R: Prop} (x : P ∧ Q ∧ R ∧ R) : Q ∧ P ∧ R := by hint
example {a b : ℚ} (h : a < b) : ¬ b < a := by hint
example : 37^2 - 35^2 = 72 * 2 := by hint
example : Nat.Prime 37 := by hint
```

Tries out any tactics registered using `register_hint tac`, and reports which ones succeed using the new "Try these: " multiple suggestion widgets. Tactics that close the goal are highlighted in green. Tactics that succeed but don't close the goal display the new subgoals in the widget. If `tac` produces a "Try this: " message, use that instead of `tac`.

I haven't hooked up `aesop` yet, because of leanprover-community/aesop#85. Similarly for `norm_num`.

I would like to parallelize this, but I don't think that needs to happen right away.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Co-authored-by: Komyyy <pol_tta@outlook.jp>
grunweg pushed a commit that referenced this pull request Dec 15, 2023
```
example (h : 1 < 0) : False := by hint
example {P Q : Prop} (p : P) (f : P → Q) : Q := by hint
example {P Q R: Prop} (x : P ∧ Q ∧ R ∧ R) : Q ∧ P ∧ R := by hint
example {a b : ℚ} (h : a < b) : ¬ b < a := by hint
example : 37^2 - 35^2 = 72 * 2 := by hint
example : Nat.Prime 37 := by hint
```

Tries out any tactics registered using `register_hint tac`, and reports which ones succeed using the new "Try these: " multiple suggestion widgets. Tactics that close the goal are highlighted in green. Tactics that succeed but don't close the goal display the new subgoals in the widget. If `tac` produces a "Try this: " message, use that instead of `tac`.

I haven't hooked up `aesop` yet, because of leanprover-community/aesop#85. Similarly for `norm_num`.

I would like to parallelize this, but I don't think that needs to happen right away.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Co-authored-by: Komyyy <pol_tta@outlook.jp>
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants