Skip to content

Commit 13b5722

Browse files
committed
fix(Tactic/Simps): use capital letter for namespace (#647)
* Custom simps projections now are declared as `def MyStructure.Simps.myProjection` instead of `def MyStructure.simps.myProjection`. This declaration was already used in the library multiple times, even though it did nothing before. * Use `symm_apply` instead of `symmApply` for lemmas generated by `simps`. * Remove custom `simps` projection for `Subtype`. It did nothing, since coercions expand to `Subtype.val`. (Do we also want to rename the generated lemmas to `foo_val` instead of `foo_coe`?) * Simplify some proofs using definitional eta for structures
1 parent 4ee6f3d commit 13b5722

File tree

4 files changed

+34
-38
lines changed

4 files changed

+34
-38
lines changed

Mathlib/Data/Subtype.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ namespace Subtype
2828

2929
variable {α β γ : Sort _} {p q : α → Prop}
3030

31-
/-- See Note [custom simps projection] -/
32-
def Simps.coe (x : Subtype p) : α :=
33-
x
34-
3531
initialize_simps_projections Subtype (val → coe)
3632

3733
/-- A version of `x.property` or `x.2` where `p` is syntactically applied to the coercion of `x`

Mathlib/Logic/Equiv/Defs.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ instance inhabited' : Inhabited (α ≃ α) := ⟨Equiv.refl α⟩
132132
protected def symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun, e.right_inv, e.left_inv⟩
133133

134134
/-- See Note [custom simps projection] -/
135-
def Simps.symmApply (e : α ≃ β) : β → α := e.symm
135+
def Simps.symm_apply (e : α ≃ β) : β → α := e.symm
136136

137-
initialize_simps_projections Equiv (toFun → apply, invFun → symmApply)
137+
initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply)
138138

139139
/-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/
140140
-- Porting note: `trans` attribute rejects this lemma because of implicit arguments.
@@ -545,20 +545,20 @@ end
545545
section
546546

547547
/-- A `PSigma`-type is equivalent to the corresponding `Sigma`-type. -/
548-
@[simps apply symmApply]
548+
@[simps apply symm_apply]
549549
def psigmaEquivSigma {α} (β : α → Type _) : (Σ' i, β i) ≃ Σ i, β i where
550550
toFun a := ⟨a.1, a.2
551551
invFun a := ⟨a.1, a.2
552-
left_inv | ⟨_, _⟩ => rfl
553-
right_inv | ⟨_, _⟩ => rfl
552+
left_inv _ := rfl
553+
right_inv _ := rfl
554554

555555
/-- A `psigma`-type is equivalent to the corresponding `sigma`-type. -/
556-
@[simps apply symmApply]
556+
@[simps apply symm_apply]
557557
def psigmaEquivSigmaPLift {α} (β : α → Sort _) : (Σ' i, β i) ≃ Σ i : PLift α, PLift (β i.down) where
558558
toFun a := ⟨PLift.up a.1, PLift.up a.2
559559
invFun a := ⟨a.1.down, a.2.down⟩
560-
left_inv | ⟨_, _⟩ => rfl
561-
right_inv | ⟨_, _⟩ => rfl
560+
left_inv _ := rfl
561+
right_inv _ := rfl
562562
#align equiv.psigma_equiv_sigma_plift Equiv.psigmaEquivSigmaPLift
563563

564564
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ' a, β₁ a` and
@@ -684,7 +684,7 @@ def sigmaCongr {α₁ α₂} {β₁ : α₁ → Sort _} {β₂ : α₂ → Sort
684684
(sigmaCongrRight F).trans (sigmaCongrLeft f)
685685

686686
/-- `sigma` type with a constant fiber is equivalent to the product. -/
687-
@[simps apply symmApply] def sigmaEquivProd (α β : Type _) : (Σ _ : α, β) ≃ α × β :=
687+
@[simps apply symm_apply] def sigmaEquivProd (α β : Type _) : (Σ _ : α, β) ≃ α × β :=
688688
fun a => ⟨a.1, a.2⟩, fun a => ⟨a.1, a.2⟩, fun ⟨_, _⟩ => rfl, fun ⟨_, _⟩ => rfl⟩
689689

690690
/-- If each fiber of a `sigma` type is equivalent to a fixed type, then the sigma type

Mathlib/Tactic/Simps/Basic.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ derives two `simp` lemmas:
179179
notation is used instead of the corresponding projection.
180180
[TODO: not yet implemented for heterogenous operations like `HMul` and `HAdd`]
181181
* You can specify custom projections, by giving a declaration with name
182-
`{StructureName}.simps.{projectionName}`. See Note [custom simps projection].
182+
`{StructureName}.Simps.{projectionName}`. See Note [custom simps projection].
183183
184184
Example:
185185
```lean
186-
def Equiv.simps.invFun (e : α ≃ β) : β → α := e.symm
186+
def Equiv.Simps.invFun (e : α ≃ β) : β → α := e.symm
187187
@[simps] def Equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ :=
188188
⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩
189189
```
@@ -339,13 +339,13 @@ Some common uses:
339339
then you have to specify explicitly that you want to use a coercion
340340
as a custom projection. For example
341341
```
342-
def relEmbedding.simps.apply (h : r ↪r s) : α → β := h
342+
def relEmbedding.Simps.apply (h : r ↪r s) : α → β := h
343343
initialize_simps_projections relEmbedding (to_embedding_toFun → apply, -to_embedding)
344344
```
345345
* If you have an isomorphism-like structure (like `Equiv`) you often want to define a custom
346346
projection for the inverse:
347347
```
348-
def Equiv.simps.symm_apply (e : α ≃ β) : β → α := e.symm
348+
def Equiv.Simps.symm_apply (e : α ≃ β) : β → α := e.symm
349349
initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply)
350350
```
351351
-/
@@ -359,7 +359,7 @@ macro "initialize_simps_projections?" rest:simpsProj : command =>
359359
end Command
360360
end Lean.Parser
361361

362-
initialize registerTraceClass `simps.verbose
362+
initialize registerTraceClass `Simps.verbose
363363
initialize registerTraceClass `simps.debug
364364

365365
/-- Projection data for a single projection of a structure -/
@@ -527,7 +527,7 @@ def simpsFindCustomProjection (str : Name) (proj : ParsedProjectionData)
527527
(rawUnivs : List Level) (trc : Bool) : CoreM ParsedProjectionData := do
528528
let env ← getEnv
529529
let (rawExpr, nrs) ← MetaM.run' (getCompositeOfProjections str proj.origName.getString!)
530-
match env.find? (str ++ `simps ++ proj.newName) with
530+
match env.find? (str ++ `Simps ++ proj.newName) with
531531
| some d@(.defnInfo _) =>
532532
let customProj := d.instantiateValueLevelParams! rawUnivs
533533
if trc then
@@ -617,7 +617,7 @@ attribute instead. See the documentation for this attribute for the data this ta
617617
618618
The returned universe levels are the universe levels of the structure. For the projections there
619619
are three cases
620-
* If the declaration `{StructureName}.simps.{projectionName}` has been declared, then the value
620+
* If the declaration `{StructureName}.Simps.{projectionName}` has been declared, then the value
621621
of this declaration is used (after checking that it is definitionally equal to the actual
622622
projection. If you rename the projection name, the declaration should have the *new* projection
623623
name.
@@ -685,7 +685,7 @@ def simpsGetRawProjections (str : Name) (traceIfExists : Bool := false)
685685
library_note "custom simps projection"/--
686686
You can specify custom projections for the `@[simps]` attribute.
687687
To do this for the projection `MyStructure.originalProjection` by adding a declaration
688-
`MyStructure.simps.myProjection` that is definitionally equal to
688+
`MyStructure.Simps.myProjection` that is definitionally equal to
689689
`MyStructure.originalProjection` but has the projection in the desired (simp-normal) form.
690690
Then you can call
691691
```

test/Simps.lean

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ run_cmd liftTermElabM <| do
3434
structure Foo2 (α : Type _) : Type _ where
3535
elim : α × α
3636

37-
def Foo2.simps.elim (α : Type _) : Foo2 α → α × α := fun x => (x.elim.1, x.elim.2)
37+
def Foo2.Simps.elim (α : Type _) : Foo2 α → α × α := fun x => (x.elim.1, x.elim.2)
3838

3939
initialize_simps_projections Foo2
4040

@@ -70,7 +70,7 @@ initialize_simps_projections Top
7070

7171
structure NewTop (α β : Type _) extends Right α β, Left α
7272

73-
def NewTop.simps.newElim {α β : Type _} (x : NewTop α β) : α × α := x.elim
73+
def NewTop.Simps.newElim {α β : Type _} (x : NewTop α β) : α × α := x.elim
7474

7575
initialize_simps_projections NewTop (toRight_toFoo2_elim → newElim)
7676

@@ -578,7 +578,7 @@ instance : CoeFun (α ≃ β) (λ _ => α → β) := ⟨Equiv.toFun⟩
578578
def Equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun⟩
579579

580580
/-- See Note [custom simps projection] -/
581-
def Equiv.simps.invFun (e : α ≃ β) : β → α := e.symm
581+
def Equiv.Simps.invFun (e : α ≃ β) : β → α := e.symm
582582

583583
/-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/
584584
@[simps (config := {simpRhs := true})]
@@ -602,7 +602,7 @@ local infix:25 (priority := high) " ≃ " => FaultyManualCoercion.Equiv
602602
variable {α β γ : Sort _}
603603

604604
/-- See Note [custom simps projection] -/
605-
noncomputable def Equiv.simps.invFun (e : α ≃ β) : β → α := Classical.choice ⟨e.invFun⟩
605+
noncomputable def Equiv.Simps.invFun (e : α ≃ β) : β → α := Classical.choice ⟨e.invFun⟩
606606

607607
run_cmd liftTermElabM <| do
608608
successIfFail (simpsGetRawProjections `FaultyManualCoercion.Equiv)
@@ -628,7 +628,7 @@ instance : CoeFun (α ≃ β) (λ _ => α → β) := ⟨Equiv.toFun⟩
628628
def Equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun⟩
629629

630630
/-- See Note [custom simps projection] -/
631-
def Equiv.simps.invFun (e : α ≃ β) : β → α := e.symm
631+
def Equiv.Simps.invFun (e : α ≃ β) : β → α := e.symm
632632

633633
initialize_simps_projections Equiv
634634

@@ -660,7 +660,7 @@ instance : CoeFun (α ≃ β) (λ _ => α → β) := ⟨Equiv.toFun⟩
660660
def Equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun⟩
661661

662662
/-- See Note [custom simps projection] -/
663-
def Equiv.simps.invFun {α : Type u} {β : Type v} (e : α ≃ β) : β → α := e.symm
663+
def Equiv.Simps.invFun {α : Type u} {β : Type v} (e : α ≃ β) : β → α := e.symm
664664

665665
run_cmd liftTermElabM <| do
666666
successIfFail (simpsGetRawProjections `FaultyUniverses.Equiv)
@@ -690,7 +690,7 @@ def Equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun⟩
690690

691691
/-- See Note [custom simps projection] -/
692692
-- test: intentionally using different unvierse levels for Equiv.symm than for Equiv
693-
def Equiv.simps.invFun {α : Sort w} {β : Sort u} (e : α ≃ β) : β → α := e.symm
693+
def Equiv.Simps.invFun {α : Sort w} {β : Sort u} (e : α ≃ β) : β → α := e.symm
694694

695695
-- check whether we can generate custom projections even if the universe names don't match
696696
initialize_simps_projections Equiv
@@ -712,7 +712,7 @@ instance : CoeFun (α ≃ β) (λ _ => α → β) := ⟨Equiv.toFun⟩
712712
def Equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun⟩
713713

714714
/-- See Note [custom simps projection] -/
715-
def Equiv.simps.symm_apply (e : α ≃ β) : β → α := e.symm
715+
def Equiv.Simps.symm_apply (e : α ≃ β) : β → α := e.symm
716716

717717
initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply)
718718

@@ -752,7 +752,7 @@ instance : CoeFun (α ≃ β) (λ _ => α → β) := ⟨Equiv.toFun⟩
752752
def Equiv.symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun⟩
753753

754754
/-- See Note [custom simps projection] -/
755-
def Equiv.simps.symm_apply (e : α ≃ β) : β → α := e.symm
755+
def Equiv.Simps.symm_apply (e : α ≃ β) : β → α := e.symm
756756
initialize_simps_projections Equiv (toFun → coe as_prefix, invFun → symm_apply)
757757

758758
run_cmd liftTermElabM <| do
@@ -999,8 +999,8 @@ def DecoratedEquiv.symm {α β : Sort _} (e : DecoratedEquiv α β) : DecoratedE
999999
P_toFun := e.P_invFun
10001000
P_invFun := e.P_toFun }
10011001

1002-
def DecoratedEquiv.simps.apply {α β : Sort _} (e : DecoratedEquiv α β) : α → β := e
1003-
def DecoratedEquiv.simps.symm_apply {α β : Sort _} (e : DecoratedEquiv α β) : β → α := e.symm
1002+
def DecoratedEquiv.Simps.apply {α β : Sort _} (e : DecoratedEquiv α β) : α → β := e
1003+
def DecoratedEquiv.Simps.symm_apply {α β : Sort _} (e : DecoratedEquiv α β) : β → α := e.symm
10041004

10051005
initialize_simps_projections DecoratedEquiv
10061006
(toEquiv'_toFun → apply, toEquiv'_invFun → symm_apply, -toEquiv')
@@ -1052,8 +1052,8 @@ def FurtherDecoratedEquiv.symm {α β : Sort _} (e : FurtherDecoratedEquiv α β
10521052
Q_toFun := e.Q_invFun
10531053
Q_invFun := e.Q_toFun }
10541054

1055-
def FurtherDecoratedEquiv.simps.apply {α β : Sort _} (e : FurtherDecoratedEquiv α β) : α → β := e
1056-
def FurtherDecoratedEquiv.simps.symm_apply {α β : Sort _} (e : FurtherDecoratedEquiv α β) :
1055+
def FurtherDecoratedEquiv.Simps.apply {α β : Sort _} (e : FurtherDecoratedEquiv α β) : α → β := e
1056+
def FurtherDecoratedEquiv.Simps.symm_apply {α β : Sort _} (e : FurtherDecoratedEquiv α β) :
10571057
β → α := e.symm
10581058

10591059
initialize_simps_projections FurtherDecoratedEquiv
@@ -1091,8 +1091,8 @@ def OneMore.symm {α β : Sort _} (e : OneMore α β) :
10911091
OneMore β α :=
10921092
{ toFurtherDecoratedEquiv := e.toFurtherDecoratedEquiv.symm }
10931093

1094-
def OneMore.simps.apply {α β : Sort _} (e : OneMore α β) : α → β := e
1095-
def OneMore.simps.symm_apply {α β : Sort _} (e : OneMore α β) : β → α := e.symm
1094+
def OneMore.Simps.apply {α β : Sort _} (e : OneMore α β) : α → β := e
1095+
def OneMore.Simps.symm_apply {α β : Sort _} (e : OneMore α β) : β → α := e.symm
10961096

10971097
initialize_simps_projections OneMore
10981098
(toFurtherDecoratedEquiv_toDecoratedEquiv_toEquiv'_toFun → apply,
@@ -1137,7 +1137,7 @@ instance (M N : Type _) [AddMonoid M] [AddMonoid N] : CoeFun (M →+ N) (λ _ =>
11371137
class AddHomPlus [Add ι] [∀ i, AddCommMonoid (A i)] :=
11381138
(mul {i} : A i →+ A i)
11391139

1140-
def AddHomPlus.simps.apply [Add ι] [∀ i, AddCommMonoid (A i)] [AddHomPlus A] {i : ι} (x : A i) :
1140+
def AddHomPlus.Simps.apply [Add ι] [∀ i, AddCommMonoid (A i)] [AddHomPlus A] {i : ι} (x : A i) :
11411141
A i :=
11421142
AddHomPlus.mul x
11431143

@@ -1146,7 +1146,7 @@ initialize_simps_projections AddHomPlus (mul_toZeroHom_toFun → apply, -mul)
11461146
class AddHomPlus2 [Add ι] :=
11471147
(mul {i j} : A i ≃ (A j ≃ A (i + j)))
11481148

1149-
def AddHomPlus2.simps.mul [Add ι] [AddHomPlus2 A] {i j : ι}
1149+
def AddHomPlus2.Simps.mul [Add ι] [AddHomPlus2 A] {i j : ι}
11501150
(x : A i) (y : A j) : A (i + j) :=
11511151
AddHomPlus2.mul x y
11521152

0 commit comments

Comments
 (0)