The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V01. The language of Mathlib

Mathlib.Lean.Meta.CongrTheorems

22 declarations. Mathlib docs · Source

Additions to Lean.Meta.CongrTheorems

def Lean.Meta.mkHCongrWithArity' E1 #

Lean.Expr → ℕ → Lean.MetaM Lean.Meta.CongrTheorem

Generates a congruence lemma for a function f for numArgs of its arguments. The only Lean.Meta.CongrArgKind kinds that appear in such a lemma are .eq, .heq, and .subsingletonInst. The resulting lemma proves either an Eq or a HEq depending on whether the types of the LHS and RHS are equal or not.

This function is a wrapper around Lean.Meta.mkHCongrWithArity. It transforms the resulting congruence lemma by trying to automatically prove hypotheses using subsingleton lemmas, and if they are so provable they are recorded with .subsingletonInst. Note that this is slightly abusing .subsingletonInst since (1) the argument might not be for a Decidable instance and (2) the argument might not even be an instance.

class Lean.Meta.FastSubsingleton E1 #

Sort u → Prop

A version of Subsingleton with few instances. It should fail fast.

ctor Lean.Meta.FastSubsingleton.mk E0 #

∀ {α : Sort u} [inst : Subsingleton α], Lean.Meta.FastSubsingleton α

theorem Lean.Meta.FastSubsingleton.inst E1 #

∀ {α : Sort u} [self : Lean.Meta.FastSubsingleton α], Subsingleton α

The subsingleton instance.

class Lean.Meta.FastIsEmpty E1 #

Sort u → Prop

A version of IsEmpty with few instances. It should fail fast.

ctor Lean.Meta.FastIsEmpty.mk E0 #

∀ {α : Sort u} [inst : IsEmpty α], Lean.Meta.FastIsEmpty α

theorem Lean.Meta.FastIsEmpty.inst E1 #

∀ {α : Sort u} [self : Lean.Meta.FastIsEmpty α], IsEmpty α

theorem Lean.Meta.FastSubsingleton.elim E1 #

∀ {α : Sort u} [h : Lean.Meta.FastSubsingleton α] (a b : α), a = b

theorem Lean.Meta.FastSubsingleton.helim E1 #

∀ {α β : Sort u} [Lean.Meta.FastSubsingleton α], α = β → ∀ (a : α) (b : β), a ≍ b

instance Lean.Meta.instFastSubsingletonOfFastIsEmpty E0 #

∀ {α : Type u} [inst : Lean.Meta.FastIsEmpty α], Lean.Meta.FastSubsingleton α

instance Lean.Meta.instFastSubsingleton E0 #

∀ {p : Prop}, Lean.Meta.FastSubsingleton p

instance Lean.Meta.instFastSubsingletonDecidable E0 #

∀ {p : Prop}, Lean.Meta.FastSubsingleton (Decidable p)

instance Lean.Meta.instFastSubsingletonFinOfNatNat E0 #

Lean.Meta.FastSubsingleton (Fin 1)

instance Lean.Meta.instFastSubsingletonPUnit E0 #

Lean.Meta.FastSubsingleton PUnit.{u_1}

instance Lean.Meta.instFastIsEmptyEmpty E0 #

Lean.Meta.FastIsEmpty Empty

instance Lean.Meta.instFastIsEmptyFalse E0 #

Lean.Meta.FastIsEmpty False

instance Lean.Meta.instFastIsEmptyFinOfNatNat E0 #

Lean.Meta.FastIsEmpty (Fin 0)

instance Lean.Meta.instFastSubsingletonForallOfFastIsEmpty E0 #

∀ {α : Sort u} [inst : Lean.Meta.FastIsEmpty α] {β : α → Sort v}, Lean.Meta.FastSubsingleton ((x : α) → β x)

instance Lean.Meta.instFastSubsingletonForall E0 #

∀ {α : Sort u} {β : α → Sort v} [inst : ∀ (x : α), Lean.Meta.FastSubsingleton (β x)],
  Lean.Meta.FastSubsingleton ((x : α) → β x)

def Lean.Meta.withSubsingletonAsFast E1 #

{α : Type} → [Inhabited α] → ((Lean.Expr → Lean.Expr) → Lean.MetaM α) → Lean.MetaM α

Runs mx in a context where all local Subsingleton and IsEmpty instances have associated FastSubsingleton and FastIsEmpty instances. The function passed to mx eliminates these instances from expressions, since they are only locally valid inside this context.

def Lean.Meta.fastSubsingletonElim E1 #

Lean.MVarId → Lean.MetaM Bool

Like subsingletonElim but uses FastSubsingleton to fail fast.

def Lean.Meta.mkRichHCongr E1 #

Lean.Expr →
  Lean.Meta.FunInfo →
    optParam Bool false → optParam (Array Bool) #[] → optParam Bool false → Lean.MetaM Lean.Meta.CongrTheorem

mkRichHCongr fType funInfo fixedFun fixedParams forceHEq create a congruence lemma to prove that Eq/HEq (f a₁ ... aₙ) (f' a₁' ... aₙ'). The functions have type fType and the number of arguments is governed by the funInfo data. Each argument produces an Eq/HEq aᵢ aᵢ' hypothesis, but we also provide these hypotheses the additional facts that the preceding equalities have been proved (unlike in mkHCongrWithArity). The first two arguments of the resulting theorem are for f and f', followed by a proof of f = f', unless fixedFun is true (see below).

When including hypotheses about previous hypotheses, we make use of dependency information and only include relevant equalities.

The argument fty denotes the type of f. The arity of the resulting congruence lemma is controlled by the size of the info array.

For the purpose of generating nicer lemmas (to help to_additive for example), this function supports generating lemmas where certain parameters are meant to be fixed:

  • If fixedFun is false (the default) then the lemma starts with three arguments for f, f', and h : f = f'. Otherwise, if fixedFun is true then the lemma starts with just f.

  • If the fixedParams argument has true for a particular argument index, then this is a hint that the congruence lemma may use the same parameter for both sides of the equality. There is no guarantee -- it respects it if the types are equal for that parameter (i.e., if the parameter does not depend on non-fixed parameters).

If forceHEq is true then the conclusion of the generated theorem is a HEq. Otherwise it might be an Eq if the equality is homogeneous.

This is the interpretation of the CongrArgKinds in the generated congruence theorem:

  • .eq corresponds to having three arguments (x : α) (x' : α) (h : x = x'). Note that h might have additional hypotheses.
  • .heq corresponds to having three arguments (x : α) (x' : α') (h : x ≍ x') Note that h might have additional hypotheses.
  • .fixed corresponds to having a single argument (x : α) that is fixed between the LHS and RHS
  • .subsingletonInst corresponds to having two arguments (x : α) (x' : α') for which the congruence generator was able to prove that x ≍ x' already. This is a slight abuse of this CongrArgKind since this is used even for types that are not subsingleton typeclasses.

Note that the first entry in this array is for the function itself.