This PR introduces an explicit `defeq` attribute to mark theorems that can be used by `dsimp`. The benefit of an explicit attribute over the prior logic of looking at the proof body is that we can reliably omit theorem bodies across module boundaries. It also helps with intra-file parallelism. If a theorem is syntactically defined by `:= rfl`, then the attribute is assumed and need not given explicitly. This is a purely syntactic check and can be fooled, e.g. if in the current namespace, `rfl` is not actually “the” `rfl` of `Eq`. In that case, some other syntax has be used, such as `:= (rfl)`. This is also the way to go if a theorem can be proved by `defeq`, but one does not actually want `dsimp` to use this fact. The `defeq` attribute will look at the *type* of the declaration, not the body, to check if it really holds definitionally. Because of different reduction settings, this can sometimes go wrong. Then one should also write `:= (rfl)`, if one does not want this to be a defeq theorem. (If one does then this is currently not possible, but it’s probably a bad idea anyways). The `set_option debug.tactic.simp.checkDefEqAttr true`, `dsimp` will warn if could not apply a lemma due to a missing `defeq` attribute. With `set_option backward.dsimp.useDefEqAttr.get false` one can revert to the old behavior of inferring rfl-ness based on the theorem body. Both options will go away eventually (too bad we can’t mark them as deprecated right away, see #7969) Meta programs that generate theorems (e.g. equational theorems) can use `inferDefEqAttr` to set the attribute based on the theorem body of the just created declaration. This builds on #8501 to update Init to `@[expose]` a fair amount of definitions that, if not exposed, would prevent some existing `:= rfl` theorems from being `defeq` theorems. In the interest of starting backwards compatible, I exposed these function. Hopefully many can be un-exposed later again. A mathlib adaption branch exists that includes both the meta programming fixes and changes to the theorems (e.g. changing `:= by rfl` to `:= rfl`). With the module system there is now no special handling for `defeq` theorem bodies, because we don’t look at the body anymore. The previous hack is removed. The `defeq`-ness of the theorem needs to be checked in the context of the theorem’s *type*; the error message contains a hint if the defeq check fails because of the exported context.
138 lines
3.6 KiB
Text
138 lines
3.6 KiB
Text
module
|
|
|
|
prelude
|
|
import all Module.Basic
|
|
|
|
/-! `import all` should import private information, privately. -/
|
|
|
|
/--
|
|
info: theorem t : f = 1 :=
|
|
testSorry
|
|
-/
|
|
#guard_msgs in
|
|
#print t
|
|
|
|
/--
|
|
error: type mismatch
|
|
y
|
|
has type
|
|
Vector Unit 1 : Type
|
|
but is expected to have type
|
|
Vector Unit f : Type
|
|
-/
|
|
#guard_msgs in
|
|
theorem v (x : Vector Unit f) (y : Vector Unit 1) : x = y := sorry
|
|
|
|
/-- error: dsimp made no progress -/
|
|
#guard_msgs in
|
|
example : P f := by dsimp only [t]; exact hP1
|
|
example : P f := by simp only [t]; exact hP1
|
|
|
|
/-- error: dsimp made no progress -/
|
|
#guard_msgs in
|
|
example : P f := by dsimp only [trfl]; exact hP1
|
|
/-- error: dsimp made no progress -/
|
|
#guard_msgs in
|
|
example : P f := by dsimp only [trfl']; exact hP1
|
|
|
|
/--
|
|
error: unknown identifier 'trflprivate'
|
|
---
|
|
error: dsimp made no progress
|
|
-/
|
|
#guard_msgs in
|
|
example : P f := by dsimp only [trflprivate]; exact hP1
|
|
/--
|
|
error: unknown identifier 'trflprivate''
|
|
---
|
|
error: dsimp made no progress
|
|
-/
|
|
#guard_msgs in
|
|
example : P f := by dsimp only [trflprivate']; exact hP1
|
|
|
|
|
|
example : P fexp := by dsimp only [fexp_trfl]; exact hP1
|
|
example : P fexp := by dsimp only [fexp_trfl']; exact hP1
|
|
|
|
|
|
/-- info: @[defeq] private theorem f.eq_def : f = 1 -/
|
|
#guard_msgs in #print sig f.eq_def
|
|
|
|
/-- info: @[defeq] private theorem f.eq_unfold : f = 1 -/
|
|
#guard_msgs in #print sig f.eq_unfold
|
|
|
|
/-- info: @[defeq] private theorem f_struct.eq_1 : f_struct 0 = 0 -/
|
|
#guard_msgs in #print sig f_struct.eq_1
|
|
|
|
/--
|
|
info: private theorem f_struct.eq_def : ∀ (x : Nat),
|
|
f_struct x =
|
|
match x with
|
|
| 0 => 0
|
|
| n.succ => f_struct n
|
|
-/
|
|
#guard_msgs in #print sig f_struct.eq_def
|
|
|
|
/--
|
|
info: private theorem f_struct.eq_unfold : f_struct = fun x =>
|
|
match x with
|
|
| 0 => 0
|
|
| n.succ => f_struct n
|
|
-/
|
|
#guard_msgs in #print sig f_struct.eq_unfold
|
|
|
|
/-- info: private theorem f_wfrec.eq_1 : ∀ (x : Nat), f_wfrec 0 x = x -/
|
|
#guard_msgs(pass trace, all) in #print sig f_wfrec.eq_1
|
|
|
|
/--
|
|
info: private theorem f_wfrec.eq_def : ∀ (x x_1 : Nat),
|
|
f_wfrec x x_1 =
|
|
match x, x_1 with
|
|
| 0, acc => acc
|
|
| n.succ, acc => f_wfrec n (acc + 1)
|
|
-/
|
|
#guard_msgs(pass trace, all) in #print sig f_wfrec.eq_def
|
|
|
|
/--
|
|
info: private theorem f_wfrec.eq_unfold : f_wfrec = fun x x_1 =>
|
|
match x, x_1 with
|
|
| 0, acc => acc
|
|
| n.succ, acc => f_wfrec n (acc + 1)
|
|
-/
|
|
#guard_msgs(pass trace, all) in #print sig f_wfrec.eq_unfold
|
|
|
|
/--
|
|
info: theorem f_wfrec.induct_unfolding : ∀ (motive : Nat → Nat → Nat → Prop),
|
|
(∀ (acc : Nat), motive 0 acc acc) →
|
|
(∀ (n acc : Nat), motive n (acc + 1) (f_wfrec n (acc + 1)) → motive n.succ acc (f_wfrec n (acc + 1))) →
|
|
∀ (a a_1 : Nat), motive a a_1 (f_wfrec a a_1)
|
|
-/
|
|
#guard_msgs(pass trace, all) in #print sig f_wfrec.induct_unfolding
|
|
|
|
/-- info: theorem f_exp_wfrec.eq_1 : ∀ (x : Nat), f_exp_wfrec 0 x = x -/
|
|
#guard_msgs in #print sig f_exp_wfrec.eq_1
|
|
|
|
/--
|
|
info: theorem f_exp_wfrec.eq_def : ∀ (x x_1 : Nat),
|
|
f_exp_wfrec x x_1 =
|
|
match x, x_1 with
|
|
| 0, acc => acc
|
|
| n.succ, acc => f_exp_wfrec n (acc + 1)
|
|
-/
|
|
#guard_msgs in #print sig f_exp_wfrec.eq_def
|
|
|
|
/--
|
|
info: theorem f_exp_wfrec.eq_unfold : f_exp_wfrec = fun x x_1 =>
|
|
match x, x_1 with
|
|
| 0, acc => acc
|
|
| n.succ, acc => f_exp_wfrec n (acc + 1)
|
|
-/
|
|
#guard_msgs in #print sig f_exp_wfrec.eq_unfold
|
|
|
|
/--
|
|
info: theorem f_exp_wfrec.induct_unfolding : ∀ (motive : Nat → Nat → Nat → Prop),
|
|
(∀ (acc : Nat), motive 0 acc acc) →
|
|
(∀ (n acc : Nat), motive n (acc + 1) (f_exp_wfrec n (acc + 1)) → motive n.succ acc (f_exp_wfrec n (acc + 1))) →
|
|
∀ (a a_1 : Nat), motive a a_1 (f_exp_wfrec a a_1)
|
|
-/
|
|
#guard_msgs(pass trace, all) in #print sig f_exp_wfrec.induct_unfolding
|