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 / V34. The tactics of Mathlib

Mathlib.Tactic.ClickSuggestions.FindPremises

27 declarations. Mathlib docs · Source

Generating a shortlist of candidate lemmas for suggestions

Discrimination tree lookup

This file defines how to build and match with the discrimination trees, for premises that are

  • imported
  • from the current module
  • local hypotheses

Performance note

When importing all of mathlib, building the discrimination trees takes on the order of 10-15 seconds. This is because of two distinct performance bottlenecks:

  1. Looping through the environment, and computing all of the discrimination tree entries is expensive, and is done in parallel to speed it up.
  2. Building the final discrimination tree by inserting all of the computed entries is less expensive, but it cannot be done in parallel, because a single datastructure is being built.

These two bottlenecks cost about the same amount of time. Luckily, we can already start doing (2) as soon as any of the parallel tasks from (1) have finished. So, we build the discrimination tree (on the main thread) at the same time that the entries are being computed on various parallel threads.

theorem Mathlib.Tactic.ClickSuggestions.PreDiscrTrees.mk.injEq E0 #

∀ (rw : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.RwLemma)
  (grw : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.GrwLemma)
  (app : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyLemma)
  (appAt : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyAtLemma)
  (rw_1 : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.RwLemma)
  (grw_1 : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.GrwLemma)
  (app_1 : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyLemma)
  (appAt_1 : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyAtLemma),
  ({ rw := rw, grw := grw, app := app, appAt := appAt } =
      { rw := rw_1, grw := grw_1, app := app_1, appAt := appAt_1 }) =
    (rw = rw_1 ∧ grw = grw_1 ∧ app = app_1 ∧ appAt = appAt_1)

theorem Mathlib.Tactic.ClickSuggestions.Choice.mk.injEq E0 #

∀ (rw grw app appAt rw_1 grw_1 app_1 appAt_1 : Bool),
  ({ rw := rw, grw := grw, app := app, appAt := appAt } =
      { rw := rw_1, grw := grw_1, app := app_1, appAt := appAt_1 }) =
    (rw = rw_1 ∧ grw = grw_1 ∧ app = app_1 ∧ appAt = appAt_1)

def Mathlib.Tactic.ClickSuggestions.Choice.ctorIdx E1 #

Mathlib.Tactic.ClickSuggestions.Choice → ℕ

def Mathlib.Tactic.ClickSuggestions.PreDiscrTrees.ctorIdx E1 #

Mathlib.Tactic.ClickSuggestions.PreDiscrTrees → ℕ

theorem Mathlib.Tactic.ClickSuggestions.PreDiscrTrees.mk.inj E1 #

∀ {rw : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.RwLemma}
  {grw : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.GrwLemma}
  {app : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyLemma}
  {appAt : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyAtLemma}
  {rw_1 : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.RwLemma}
  {grw_1 : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.GrwLemma}
  {app_1 : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyLemma}
  {appAt_1 : Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyAtLemma},
  { rw := rw, grw := grw, app := app, appAt := appAt } = { rw := rw_1, grw := grw_1, app := app_1, appAt := appAt_1 } →
    rw = rw_1 ∧ grw = grw_1 ∧ app = app_1 ∧ appAt = appAt_1

theorem Mathlib.Tactic.ClickSuggestions.Choice.mk.inj E1 #

∀ {rw grw app appAt rw_1 grw_1 app_1 appAt_1 : Bool},
  { rw := rw, grw := grw, app := app, appAt := appAt } = { rw := rw_1, grw := grw_1, app := app_1, appAt := appAt_1 } →
    rw = rw_1 ∧ grw = grw_1 ∧ app = app_1 ∧ appAt = appAt_1

structure Mathlib.Tactic.ClickSuggestions.Choice E1 #

Type

A choice of which discrimination trees to build.

ctor Mathlib.Tactic.ClickSuggestions.Choice.mk E0 #

Bool → Bool → Bool → Bool → Mathlib.Tactic.ClickSuggestions.Choice

abbrev Mathlib.Tactic.ClickSuggestions.Choice.rw E1 #

Mathlib.Tactic.ClickSuggestions.Choice → Bool

Build the rw discrimination tree?

abbrev Mathlib.Tactic.ClickSuggestions.Choice.grw E1 #

Mathlib.Tactic.ClickSuggestions.Choice → Bool

Build the grw discrimination tree?

abbrev Mathlib.Tactic.ClickSuggestions.Choice.app E1 #

Mathlib.Tactic.ClickSuggestions.Choice → Bool

Build the apply discrimination tree?

abbrev Mathlib.Tactic.ClickSuggestions.Choice.appAt E1 #

Mathlib.Tactic.ClickSuggestions.Choice → Bool

Build the apply at discrimination tree?

structure Mathlib.Tactic.ClickSuggestions.PreDiscrTrees E1 #

Type

Structure used for constructing the root nodes of the 4 discrimination trees.

ctor Mathlib.Tactic.ClickSuggestions.PreDiscrTrees.mk E0 #

Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.RwLemma →
  Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.GrwLemma →
    Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyLemma →
      Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyAtLemma →
        Mathlib.Tactic.ClickSuggestions.PreDiscrTrees

abbrev Mathlib.Tactic.ClickSuggestions.PreDiscrTrees.rw E1 #

Mathlib.Tactic.ClickSuggestions.PreDiscrTrees →
  Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.RwLemma

The rw discrimination tree root.

abbrev Mathlib.Tactic.ClickSuggestions.PreDiscrTrees.grw E1 #

Mathlib.Tactic.ClickSuggestions.PreDiscrTrees →
  Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.GrwLemma

The grw discrimination tree root.

abbrev Mathlib.Tactic.ClickSuggestions.PreDiscrTrees.app E1 #

Mathlib.Tactic.ClickSuggestions.PreDiscrTrees →
  Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyLemma

The apply discrimination tree root.

abbrev Mathlib.Tactic.ClickSuggestions.PreDiscrTrees.appAt E1 #

Mathlib.Tactic.ClickSuggestions.PreDiscrTrees →
  Lean.Meta.RefinedDiscrTree.PreDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyAtLemma

The apply at discrimination tree root.

opaque Mathlib.Tactic.ClickSuggestions.rwRef E1 #

IO.Ref (Option (Lean.Meta.RefinedDiscrTree Mathlib.Tactic.ClickSuggestions.RwLemma))

The global ref for looking up rw lemmas.

opaque Mathlib.Tactic.ClickSuggestions.grwRef E1 #

IO.Ref (Option (Lean.Meta.RefinedDiscrTree Mathlib.Tactic.ClickSuggestions.GrwLemma))

The global ref for looking up grw lemmas.

opaque Mathlib.Tactic.ClickSuggestions.appRef E1 #

IO.Ref (Option (Lean.Meta.RefinedDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyLemma))

The global ref for looking up apply lemmas.

opaque Mathlib.Tactic.ClickSuggestions.appAtRef E1 #

IO.Ref (Option (Lean.Meta.RefinedDiscrTree Mathlib.Tactic.ClickSuggestions.ApplyAtLemma))

The global ref for looking up apply at lemmas.

def Mathlib.Tactic.ClickSuggestions.computeImportDiscrTrees E1 #

Mathlib.Tactic.ClickSuggestions.Choice → Lean.CoreM Unit

Compute the discrimination trees for import theorems.

def Mathlib.Tactic.ClickSuggestions.computeModuleDiscrTrees E1 #

Mathlib.Tactic.ClickSuggestions.Choice → Option Lean.Name → Lean.CoreM Mathlib.Tactic.ClickSuggestions.PreDiscrTrees

Compute the discrimination trees for the theorems in the current file.

def Mathlib.Tactic.ClickSuggestions.computeLCtxDiscrTrees E1 #

Mathlib.Tactic.ClickSuggestions.Choice →
  Lean.LocalContext → Option Lean.FVarId → Lean.MetaM Mathlib.Tactic.ClickSuggestions.PreDiscrTrees

Compute the discrimination trees for the local variables in lctx. We restrict to the variables in lctx to avoid using introduced bound variables.

def Mathlib.Tactic.ClickSuggestions.getImportMatches E1 #

{α : Type} →
  IO.Ref (Option (Lean.Meta.RefinedDiscrTree α)) → Lean.Expr → Lean.MetaM (Lean.Meta.RefinedDiscrTree.MatchResult α)

Get the discrimination tree matches with theorems from imported files.

def Mathlib.Tactic.ClickSuggestions.getMatches E1 #

{α : Type} → Lean.Meta.RefinedDiscrTree α → Lean.Expr → Lean.MetaM (Lean.Meta.RefinedDiscrTree.MatchResult α)

Get the discrimination tree matches from tree.