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

Rewrite applies the wrong equational rule #5611

Closed
3 tasks done
BrunoDutertre opened this issue Oct 3, 2024 · 6 comments
Closed
3 tasks done

Rewrite applies the wrong equational rule #5611

BrunoDutertre opened this issue Oct 3, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@BrunoDutertre
Copy link

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

On the following example, the rw tactic does not unfold a function definition (as it used to prior to 4.12.0).

structure LoopRange where
  start: Nat
  end_: Option Nat

namespace LoopRange
def isZero (r: LoopRange): Prop :=
  r = ⟨0, some 0def isZeroVar2 (r: LoopRange): Prop :=
  match r with
  | ⟨0, some 0⟩ => True
  | _ => False

example (r: LoopRange): r.isZeroVar2 ↔ r.isZero := by
  rw [isZeroVar2]
  sorry

end LoopRange

Instead, it looks as if rw [isZeroVar2] applies isZeroVar2.eq_2 which results in two unprovable subgoals:

Tactic state
 2 goals

 r : LoopRange
 ⊢ False ↔ r.isZero

 case x_1
 r : LoopRange
 ⊢ r = { start := 0, end_ := some 0 } → False

This variant does the right thing::

example (r: LoopRange): r.isZeroVar2 ↔ r.isZero := by
  rw [isZeroVar2.eq_def]
  sorry

Versions

4.12.0

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@BrunoDutertre BrunoDutertre added the bug Something isn't working label Oct 3, 2024
@nomeata
Copy link
Contributor

nomeata commented Oct 3, 2024

I fear that's now the expected behavior. It always has been like this for recursive functions, and has become more uniform. Using rw [foo.eq_def] is the right work around.

@BrunoDutertre
Copy link
Author

In other places, I've seen an error message like this

failed to rewrite using equation theorems for 'Option.isSome'. Try rewriting with 'Option.isSome.eq_def'.

But here, it's silently applying the wrong rewrite and there's no warning or hint at what to do.

@nomeata
Copy link
Contributor

nomeata commented Oct 3, 2024

Yes, this only happens with function definitions that have a catch-all clause in the pattern match. These lead to rewrite rules that always apply, but introduce side goals. With simp that's fine, it won't apply the rule unless it can discharge these side goals. But rw is a bit too primitive for that, at least at the moment.

@Kha
Copy link
Member

Kha commented Oct 25, 2024

Closing as (new) expected behavior

@Kha Kha closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2024
@BrunoDutertre
Copy link
Author

Is this documented somewhere? What is the new expected behavior of rw [<function-name>]?

@nomeata
Copy link
Contributor

nomeata commented Oct 27, 2024

It's not new behavior of rw; it has always behaved like this with functions with multiple equational rules and overlapping patterns. Until 0.11 only recursive functions has multiple equational rules, since 0.12 all functions are treated the same in this regard. See breaking changes section in https://github.com/leanprover/lean4/releases/tag/v4.12.0 (although it's not explicitly calling out the this particular effect.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants