Skip to content

Commit 2b31a89

Browse files
committed
fix(Simps): don't reduce the type of the equality (leanprover-community#36656)
This PR fixes a small problem with `simps`, that the type in the generated equality lemmas is unnecessarily reduced. This can result in raw projections, which we typically don't want in our lemmas. This doesn't affect how these lemmas behave in `simp`. This problem confused `to_dual` a bit in `CategoryTheory.Iso`. This PR lets us remove the `respectTansparency` option there.
1 parent de4f458 commit 2b31a89

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

Mathlib/CategoryTheory/Iso.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def refl (X : C) : X ≅ X where
118118
hom := 𝟙 X
119119
inv := 𝟙 X
120120

121-
set_option backward.isDefEq.respectTransparency false in
122121
set_option linter.existingAttributeWarning false in
123122
attribute [to_dual existing refl_inv] refl_hom
124123

@@ -135,7 +134,6 @@ def trans (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z where
135134
hom := α.hom ≫ β.hom
136135
inv := β.inv ≫ α.inv
137136

138-
set_option backward.isDefEq.respectTransparency false in
139137
set_option linter.existingAttributeWarning false in
140138
attribute [to_dual existing trans_inv] trans_hom
141139

@@ -480,7 +478,6 @@ def mapIso (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.obj X ≅ F.obj Y where
480478
hom := F.map i.hom
481479
inv := F.map i.inv
482480

483-
set_option backward.isDefEq.respectTransparency false in
484481
set_option linter.existingAttributeWarning false in
485482
attribute [to_dual existing mapIso_inv] mapIso_hom
486483

Mathlib/CategoryTheory/Whiskering.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
4343

4444
set_option backward.isDefEq.respectTransparency false in
4545
/-- If `α : G ⟶ H` then `whiskerLeft F α : F ⋙ G ⟶ F ⋙ H` has components `α.app (F.obj X)`. -/
46-
@[to_dual self, simps (attr := to_dual self (reorder := G H))]
46+
@[to_dual self, simps (attr := to_dual self)]
4747
def whiskerLeft (F : C ⥤ D) {G H : D ⥤ E} (α : G ⟶ H) :
4848
F ⋙ G ⟶ F ⋙ H where
4949
app X := α.app (F.obj X)
@@ -56,7 +56,7 @@ lemma id_hcomp (F : C ⥤ D) {G H : D ⥤ E} (α : G ⟶ H) : 𝟙 F ◫ α = wh
5656

5757
set_option backward.isDefEq.respectTransparency false in
5858
/-- If `α : G ⟶ H` then `whiskerRight α F : G ⋙ F ⟶ H ⋙ F` has components `F.map (α.app X)`. -/
59-
@[to_dual self, simps (attr := to_dual self (reorder := G H))]
59+
@[to_dual self, simps (attr := to_dual self)]
6060
def whiskerRight {G H : C ⥤ D} (α : G ⟶ H) (F : D ⥤ E) :
6161
G ⋙ F ⟶ H ⋙ F where
6262
app X := F.map (α.app X)

Mathlib/Tactic/Simps/Basic.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,12 +1051,14 @@ private partial def addProjections (nm : NameStruct) (type lhs rhs : Expr)
10511051
trace[simps.debug] "Type of the Expression before normalizing: {type}"
10521052
withTransparency cfg.typeMd <| forallTelescopeReducing type fun typeArgs tgt ↦ withDefault do
10531053
trace[simps.debug] "Type after removing pi's: {tgt}"
1054-
let tgt ← whnfD tgt
1055-
trace[simps.debug] "Type after reduction: {tgt}"
1054+
-- TODO: consider reducing the type less aggressively.
1055+
-- See https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Simps.20and.20.60def.60/near/560586075
1056+
let tgtWhnf ← whnfD tgt
1057+
trace[simps.debug] "Type after reduction: {tgtWhnf}"
10561058
let newArgs := args ++ typeArgs
10571059
let lhsAp := lhs.instantiateLambdasOrApps typeArgs
10581060
let rhsAp := rhs.instantiateLambdasOrApps typeArgs
1059-
let str := tgt.getAppFn.constName
1061+
let str := tgtWhnf.getAppFn.constName
10601062
trace[simps.debug] "todo: {todo}, toApply: {toApply}"
10611063
-- We want to generate the current projection if it is in `todo`
10621064
let todoNext := todo.filter (·.1"")
@@ -1142,7 +1144,7 @@ private partial def addProjections (nm : NameStruct) (type lhs rhs : Expr)
11421144
return #[nm.toName]
11431145
-- if the value is a constructor application
11441146
trace[simps.debug] "Generating raw projection information..."
1145-
let projInfo ← getProjectionExprs ref tgt rhsWhnf cfg
1147+
let projInfo ← getProjectionExprs ref tgtWhnf rhsWhnf cfg
11461148
trace[simps.debug] "Raw projection information:{indentD m!"{projInfo}"}"
11471149
-- If we are in the middle of a composite projection.
11481150
if let idx :: rest := toApply then

MathlibTest/Simps.lean

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,3 +1272,20 @@ example : foo.1 = 2 := by
12721272
rfl
12731273

12741274
end Grind
1275+
1276+
def MyNat := Nat
1277+
1278+
def MyNat.zero : MyNat := Nat.zero
1279+
1280+
structure MyNatStruct where
1281+
n : MyNat
1282+
1283+
@[simps]
1284+
def zero : MyNatStruct where
1285+
n := MyNat.zero
1286+
1287+
-- Verify that the equality type is not reduced from `MyNat` to `Nat`:
1288+
set_option pp.explicit true in
1289+
/-- info: zero_n : @Eq MyNat zero.n MyNat.zero -/
1290+
#guard_msgs in
1291+
#check zero_n

0 commit comments

Comments
 (0)