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

feat: improve error messages and docstring for decide tactic #3422

Merged
merged 5 commits into from
Feb 27, 2024

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Feb 20, 2024

The decide tactic produces error messages that users find to be obscure. Now:

  1. If the Decidable instance reduces to isFalse, it reports that decide failed because the proposition is false.
  2. If the Decidable instance fails to reduce, it explains what proposition it failed for, and it shows the reduced Decidable instance rather than the Decidable.decide expression. That expression tends to be less useful since it shows the unreduced Decidable argument (plus it's a lot longer!)

Examples:

example : 11 := by decide
/-
tactic 'decide' proved that the proposition
  1 ≠ 1
is false
-/

opaque unknownProp : Prop

open scoped Classical in
example : unknownProp := by decide
/-
tactic 'decide' failed for proposition
  unknownProp
since its 'Decidable' instance reduced to
  Classical.choice ⋯
rather than to the 'isTrue' constructor.
-/

When reporting the error, decide only shows the whnf of the Decidable instance. In the future we could consider having it reduce all decidable instances present in the term, which can help with determining the cause of failure (this was explored in 8cede58).

@kmill kmill requested review from Kha and kim-em as code owners February 20, 2024 19:32
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc February 20, 2024 19:45 Inactive
@kmill
Copy link
Collaborator Author

kmill commented Feb 20, 2024

@david-christiansen The decide tactic has had a confusing error message when it fails to prove the goal, and here's an attempt to improve the situation, and the documentation as well while we're here.

There was recent Zulip discussion about decide. There, there was a request to make decide synthesize a reason for the failure, but that doesn't seem to be possible to do in a satisfying amount of generality, unless we had a parallel version of Decidable whose constructors contained a reason for the success or failure. This is an idea I had that made it into LSpec.

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Feb 20, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Feb 20, 2024

Mathlib CI status (docs):

  • ❗ Std CI can not be attempted yet, as the nightly-testing-2024-02-20 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Std CI should run now. (2024-02-20 19:48:52)
  • 💥 Mathlib branch lean-pr-testing-3422 build failed against this PR. (2024-02-21 01:18:34) View Log
  • 💥 Mathlib branch lean-pr-testing-3422 build failed against this PR. (2024-02-21 02:40:08) View Log
  • 💥 Mathlib branch lean-pr-testing-3422 build failed against this PR. (2024-02-21 04:08:29) View Log
  • 💥 Mathlib branch lean-pr-testing-3422 build failed against this PR. (2024-02-21 21:29:44) View Log
  • 💥 Mathlib branch lean-pr-testing-3422 build failed against this PR. (2024-02-27 18:25:00) View Log
  • ❗ Std/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 9c00a5933944bbc4801079777dd9fcc326e66390 --onto c5fd88f5e118738425dd55b7592de435b7db8483. (2024-02-27 23:11:00)

@david-christiansen
Copy link
Contributor

This looks like a nice improvement!

I think we should look into adding reasons as optional arguments. If we do it right, we might not even break anything :-)

@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc February 21, 2024 01:03 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 21, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 21, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan full-ci labels Feb 21, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc February 21, 2024 01:59 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 21, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 21, 2024
@kmill kmill force-pushed the improve_decide_error branch 2 times, most recently from 33a50fc to 195b074 Compare February 21, 2024 03:07
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc February 21, 2024 03:16 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 21, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 21, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc February 21, 2024 20:48 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 21, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 21, 2024
@kmill kmill force-pushed the improve_decide_error branch from a9628f2 to 9372c34 Compare February 27, 2024 17:26
@kmill kmill added the awaiting-review Waiting for someone to review the PR label Feb 27, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc February 27, 2024 17:40 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Feb 27, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Feb 27, 2024
The `decide` tactic produces error messages that users find to be obscure. Now:
1.  If the `Decidable` instance reduces to `isFalse`, it reports that `decide` failed because the proposition is false.
2. If the `Decidable` instance fails to reduce, it explains what proposition it failed for, and it shows the reduced `Decidable` instance rather than the `Decidable.decide` expression, which tends to be less useful since it shows the unreduced `Decidable` argument (plus it's a lot longer!)

Examples:
```lean
example : 1 ≠ 1 := by decide
/-
tactic 'decide' proved that the proposition
  1 ≠ 1
is false
-/

opaque unknownProp : Prop

open scoped Classical in
example : unknownProp := by decide
/-
tactic 'decide' failed for proposition
  unknownProp
since its 'Decidable' instance did not reduce to the 'isTrue' constructor:
  Classical.choice ⋯
-/
```

In the future, it would be useful if `decide` would locate and report what `Decidable` instance inside the reported term is not being fully reduced.
@leodemoura
Copy link
Member

Rebased

@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc February 27, 2024 22:40 Inactive
@leodemoura leodemoura added this pull request to the merge queue Feb 27, 2024
Merged via the queue into master with commit 6e24a08 Feb 27, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants