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] - chore: better failures for linear_combination #15791

Closed
wants to merge 2 commits into from

Conversation

hrmacbeth
Copy link
Member

The implementation of linear_combination is as a macro performing effectively refine ******; ring. If the term provided to refine fails to elaborate, Lean inserts sorries where needed and then continues on to ring. This produces a confusing error message. For example, the problem

example (x y : ℤ) (h1 : x * y + 2 * x = 1) (h2 : x = y) : x * y + 2 * x = 1 := by
  linear_combination h1 + (0 : ℝ) * h2

produces both the "true" error message

application type mismatch
  Mathlib.Tactic.LinearCombination.c_mul_pf h2 0
argument
  0
has type
  ℝ : Type
but is expected to have type
  ℤ : Type

and the "tactic is confused because it persevered when it shouldn't have" error message

ring failed, ring expressions not equal
x y : ℤ
h1 : x * y + 2 * x = 1
h2 : x = y
⊢ -(x * sorryAx ℤ true) + y * sorryAx ℤ true = 0

This PR fixes this by strategically inserting a Term.withoutErrToSorry. In examples such as the above, it now stops after the refine, so the second error message does not appear.


Open in Gitpod

@hrmacbeth hrmacbeth added the t-meta Tactics, attributes or user commands label Aug 14, 2024
Copy link

PR summary 0440177643

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

No declarations were harmed in the making of this PR! 🐙

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.

@hrmacbeth hrmacbeth added the easy < 20s of review time. See the lifecycle page for guidelines. label Aug 14, 2024
@kmill
Copy link
Contributor

kmill commented Aug 15, 2024

Seems good. Maybe it could make sense to move withoutErrToSorry earlier, but where you have it currently is definitely justified since it's for elaboration of syntax generated by the tactic itself.

bors r+

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Aug 15, 2024
mathlib-bors bot pushed a commit that referenced this pull request Aug 15, 2024
The implementation of `linear_combination` is as a macro performing effectively `refine ******; ring`.  If the term provided to `refine` fails to elaborate, Lean inserts sorries where needed and then continues on to `ring`.  This produces a confusing error message.  For example, the problem
```lean
example (x y : ℤ) (h1 : x * y + 2 * x = 1) (h2 : x = y) : x * y + 2 * x = 1 := by
  linear_combination h1 + (0 : ℝ) * h2
```
produces both the "true" error message
```
application type mismatch
  Mathlib.Tactic.LinearCombination.c_mul_pf h2 0
argument
  0
has type
  ℝ : Type
but is expected to have type
  ℤ : Type
```
and the "tactic is confused because it persevered when it shouldn't have" error message
```
ring failed, ring expressions not equal
x y : ℤ
h1 : x * y + 2 * x = 1
h2 : x = y
⊢ -(x * sorryAx ℤ true) + y * sorryAx ℤ true = 0
```

This PR fixes this by strategically inserting a `Term.withoutErrToSorry`.  In examples such as the above, it now stops after the `refine`, so the second error message does not appear.
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Aug 15, 2024

Build failed (retrying...):

mathlib-bors bot pushed a commit that referenced this pull request Aug 16, 2024
The implementation of `linear_combination` is as a macro performing effectively `refine ******; ring`.  If the term provided to `refine` fails to elaborate, Lean inserts sorries where needed and then continues on to `ring`.  This produces a confusing error message.  For example, the problem
```lean
example (x y : ℤ) (h1 : x * y + 2 * x = 1) (h2 : x = y) : x * y + 2 * x = 1 := by
  linear_combination h1 + (0 : ℝ) * h2
```
produces both the "true" error message
```
application type mismatch
  Mathlib.Tactic.LinearCombination.c_mul_pf h2 0
argument
  0
has type
  ℝ : Type
but is expected to have type
  ℤ : Type
```
and the "tactic is confused because it persevered when it shouldn't have" error message
```
ring failed, ring expressions not equal
x y : ℤ
h1 : x * y + 2 * x = 1
h2 : x = y
⊢ -(x * sorryAx ℤ true) + y * sorryAx ℤ true = 0
```

This PR fixes this by strategically inserting a `Term.withoutErrToSorry`.  In examples such as the above, it now stops after the `refine`, so the second error message does not appear.
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Aug 16, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title chore: better failures for linear_combination [Merged by Bors] - chore: better failures for linear_combination Aug 16, 2024
@mathlib-bors mathlib-bors bot closed this Aug 16, 2024
@mathlib-bors mathlib-bors bot deleted the HM-linear-combination-bug branch August 16, 2024 01:08
bjoernkjoshanssen pushed a commit that referenced this pull request Sep 9, 2024
The implementation of `linear_combination` is as a macro performing effectively `refine ******; ring`.  If the term provided to `refine` fails to elaborate, Lean inserts sorries where needed and then continues on to `ring`.  This produces a confusing error message.  For example, the problem
```lean
example (x y : ℤ) (h1 : x * y + 2 * x = 1) (h2 : x = y) : x * y + 2 * x = 1 := by
  linear_combination h1 + (0 : ℝ) * h2
```
produces both the "true" error message
```
application type mismatch
  Mathlib.Tactic.LinearCombination.c_mul_pf h2 0
argument
  0
has type
  ℝ : Type
but is expected to have type
  ℤ : Type
```
and the "tactic is confused because it persevered when it shouldn't have" error message
```
ring failed, ring expressions not equal
x y : ℤ
h1 : x * y + 2 * x = 1
h2 : x = y
⊢ -(x * sorryAx ℤ true) + y * sorryAx ℤ true = 0
```

This PR fixes this by strategically inserting a `Term.withoutErrToSorry`.  In examples such as the above, it now stops after the `refine`, so the second error message does not appear.
bjoernkjoshanssen pushed a commit that referenced this pull request Sep 9, 2024
The implementation of `linear_combination` is as a macro performing effectively `refine ******; ring`.  If the term provided to `refine` fails to elaborate, Lean inserts sorries where needed and then continues on to `ring`.  This produces a confusing error message.  For example, the problem
```lean
example (x y : ℤ) (h1 : x * y + 2 * x = 1) (h2 : x = y) : x * y + 2 * x = 1 := by
  linear_combination h1 + (0 : ℝ) * h2
```
produces both the "true" error message
```
application type mismatch
  Mathlib.Tactic.LinearCombination.c_mul_pf h2 0
argument
  0
has type
  ℝ : Type
but is expected to have type
  ℤ : Type
```
and the "tactic is confused because it persevered when it shouldn't have" error message
```
ring failed, ring expressions not equal
x y : ℤ
h1 : x * y + 2 * x = 1
h2 : x = y
⊢ -(x * sorryAx ℤ true) + y * sorryAx ℤ true = 0
```

This PR fixes this by strategically inserting a `Term.withoutErrToSorry`.  In examples such as the above, it now stops after the `refine`, so the second error message does not appear.
bjoernkjoshanssen pushed a commit that referenced this pull request Sep 12, 2024
The implementation of `linear_combination` is as a macro performing effectively `refine ******; ring`.  If the term provided to `refine` fails to elaborate, Lean inserts sorries where needed and then continues on to `ring`.  This produces a confusing error message.  For example, the problem
```lean
example (x y : ℤ) (h1 : x * y + 2 * x = 1) (h2 : x = y) : x * y + 2 * x = 1 := by
  linear_combination h1 + (0 : ℝ) * h2
```
produces both the "true" error message
```
application type mismatch
  Mathlib.Tactic.LinearCombination.c_mul_pf h2 0
argument
  0
has type
  ℝ : Type
but is expected to have type
  ℤ : Type
```
and the "tactic is confused because it persevered when it shouldn't have" error message
```
ring failed, ring expressions not equal
x y : ℤ
h1 : x * y + 2 * x = 1
h2 : x = y
⊢ -(x * sorryAx ℤ true) + y * sorryAx ℤ true = 0
```

This PR fixes this by strategically inserting a `Term.withoutErrToSorry`.  In examples such as the above, it now stops after the `refine`, so the second error message does not appear.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy < 20s of review time. See the lifecycle page for guidelines. 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.

2 participants