This PR introduces stricter inference for the `@[defeq]` attribute and a companion `@[backward_defeq]` attribute that preserves the pre-PR behavior as an opt-in. ### What changed * `@[defeq]` is now inferred only when the equation holds at `.instances` transparency (the transparency `dsimp` operates at). * `@[backward_defeq]` is the old set: every theorem whose `rfl` proof the legacy inference would have accepted is tagged `@[backward_defeq]`, so `defeq ⊆ backward_defeq` holds by construction. * The option `backward.defeqAttrib.useBackward` (default `false`) makes `dsimp` also use `@[backward_defeq]` theorems, restoring the pre-PR behavior for a specific proof or file. * The option is eqn-affecting: its value at the point of a function's definition is recorded so that the equation lemmas later generated for that function use the same value, regardless of the ambient option at the use site. ### Mathlib adaption A companion adaption branch (`lean-pr-testing-backward-defeq-attrib` on mathlib4) builds cleanly against this PR and passes `lake test` without warnings. Most adaption changes are scoped `set_option backward.defeqAttrib.useBackward true in` additions on the failing declarations; a small number of files needed proof-level edits where the stored form of a `dsimp%`/`@[reassoc]`/`@[elementwise]` /`@[simps]`/`@[to_app]`-generated lemma had drifted under the stricter regime. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
45 lines
864 B
Text
45 lines
864 B
Text
def Nat.isZero (x : Nat) : Bool :=
|
|
match x with
|
|
| 0 => true
|
|
| _+1 => false
|
|
|
|
axiom P : Bool → Prop
|
|
axiom P_false : P false
|
|
|
|
/--
|
|
trace: x : Nat
|
|
⊢ P (1 + x).isZero
|
|
-/
|
|
#guard_msgs in
|
|
example (x : Nat) : P (1 + id x.succ.pred).isZero := by
|
|
dsimp
|
|
trace_state
|
|
simp [Nat.succ_add]
|
|
dsimp [Nat.isZero]
|
|
apply P_false
|
|
|
|
example (x : Nat) : P (id x.succ.succ).isZero := by
|
|
dsimp [Nat.isZero]
|
|
apply P_false
|
|
|
|
/--
|
|
trace: x : Nat
|
|
⊢ P false
|
|
-/
|
|
#guard_msgs in
|
|
set_option backward.defeqAttrib.useBackward true in
|
|
example (x : Nat) : P (id x.succ.succ).isZero := by
|
|
dsimp [Nat.isZero.eq_2]
|
|
trace_state
|
|
apply P_false
|
|
|
|
example (x : Nat) : P (id x.succ.succ).isZero := by
|
|
dsimp!
|
|
apply P_false
|
|
|
|
@[simp] theorem isZero_succ (x : Nat) : (x + 1).isZero = false :=
|
|
rfl
|
|
|
|
theorem ex1 (x : Nat) : P (id x.succ.succ.pred).isZero := by
|
|
dsimp
|
|
apply P_false
|