lean4-htt/src/Lean/Meta.lean
Joachim Breitner 88fa4212d7
feat: @[method_specs] to generate specification theorems from class instances (#10302)
This PR introduces the `@[specs]` attribute. It can be applied to
(certain) type class instances and define “specification theorems” for
the class’ operations, by taking the equational theorems of the
implementation function mentioned in the type class instance and
rephrasing them in terms of the overloaded operations. Fixes #5295.

Example:

```
inductive L α where
  | nil  : L α
  | cons : α → L α → L α

def L.beqImpl [BEq α] : L α → L α → Bool
  | nil, nil           => true
  | cons x xs, cons y ys => x == y && L.beqImpl xs ys
  | _, _               => false

@[method_specs] instance [BEq α] : BEq (L α) := ⟨L.beqImpl⟩

/--
info: theorem instBEqL.beq_spec_2.{u_1} : ∀ {α : Type u_1} [inst : BEq α] (x_2 : α) (xs : L α) (y : α) (ys : L α),
  (L.cons x_2 xs == L.cons y ys) = (x_2 == y && xs == ys)
-/
#guard_msgs(pass trace, all) in
#print sig instBEqL.beq_spec_2
```

It also introduces the `method_specs_norm` simpset to allow registering
further normalization of the theorems. The intended use of this is to
rewrite, say, `Append.append` to the `HAppend.hAppend` (i.e. `++`) that
the user wants to see. Library annotations to follow in a separate PR.
2025-09-15 11:17:06 +00:00

60 lines
1.9 KiB
Text

/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
module
prelude
public import Lean.Meta.Basic
public import Lean.Meta.LevelDefEq
public import Lean.Meta.WHNF
public import Lean.Meta.InferType
public import Lean.Meta.FunInfo
public import Lean.Meta.ExprDefEq
public import Lean.Meta.DecLevel
public import Lean.Meta.DiscrTree
public import Lean.Meta.Reduce
public import Lean.Meta.Instances
public import Lean.Meta.AbstractMVars
public import Lean.Meta.SynthInstance
public import Lean.Meta.AppBuilder
public import Lean.Meta.Sorry
public import Lean.Meta.Tactic
public import Lean.Meta.KAbstract
public import Lean.Meta.RecursorInfo
public import Lean.Meta.GeneralizeTelescope
public import Lean.Meta.Match
public import Lean.Meta.ReduceEval
public import Lean.Meta.Closure
public import Lean.Meta.AbstractNestedProofs
public import Lean.Meta.LetToHave
public import Lean.Meta.ForEachExpr
public import Lean.Meta.Transform
public import Lean.Meta.PPGoal
public import Lean.Meta.UnificationHint
public import Lean.Meta.Inductive
public import Lean.Meta.SizeOf
public import Lean.Meta.IndPredBelow
public import Lean.Meta.Coe
public import Lean.Meta.CollectFVars
public import Lean.Meta.GeneralizeVars
public import Lean.Meta.Injective
public import Lean.Meta.Structure
public import Lean.Meta.Constructions
public import Lean.Meta.CongrTheorems
public import Lean.Meta.Eqns
public import Lean.Meta.ExprLens
public import Lean.Meta.ExprTraverse
public import Lean.Meta.Eval
public import Lean.Meta.CoeAttr
public import Lean.Meta.Iterator
public import Lean.Meta.LazyDiscrTree
public import Lean.Meta.LitValues
public import Lean.Meta.CheckTactic
public import Lean.Meta.Canonicalizer
public import Lean.Meta.Diagnostics
public import Lean.Meta.BinderNameHint
public import Lean.Meta.TryThis
public import Lean.Meta.Hint
public import Lean.Meta.MethodSpecs